Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

TQPushButton Class Reference

The TQPushButton widget provides a command button. More...

#include <ntqpushbutton.h>

Inherits TQButton.

List of all member functions.

Public Members

Public Slots

Important Inherited Members

Properties


Detailed Description

The TQPushButton widget provides a command button.

The push button, or command button, is perhaps the most commonly used widget in any graphical user interface. Push (click) a button to command the computer to perform some action, or to answer a question. Typical buttons are OK, Apply, Cancel, Close, Yes, No and Help.

A command button is rectangular and typically displays a text label describing its action. An underlined character in the label (signified by preceding it with an ampersand in the text) indicates an accelerator key, e.g.

        TQPushButton *pb = new TQPushButton( "&Download", this );
    
In this example the accelerator is Alt+D, and the label text will be displayed as Download.

Push buttons can display a textual label or a pixmap, and optionally a small icon. These can be set using the constructors and changed later using setText(), setPixmap() and setIconSet(). If the button is disabled the appearance of the text or pixmap and iconset will be manipulated with respect to the GUI style to make the button look "disabled".

A push button emits the signal clicked() when it is activated by the mouse, the Spacebar or by a keyboard accelerator. Connect to this signal to perform the button's action. Push buttons also provide less commonly used signals, for example, pressed() and released().

Command buttons in dialogs are by default auto-default buttons, i.e. they become the default push button automatically when they receive the keyboard input focus. A default button is a push button that is activated when the user presses the Enter or Return key in a dialog. You can change this with setAutoDefault(). Note that auto-default buttons reserve a little extra space which is necessary to draw a default-button indicator. If you do not want this space around your buttons, call setAutoDefault(FALSE).

Being so central, the button widget has grown to accommodate a great many variations in the past decade. The Microsoft style guide now shows about ten different states of Windows push buttons and the text implies that there are dozens more when all the combinations of features are taken into consideration.

The most important modes or states are:

As a general rule, use a push button when the application or dialog window performs an action when the user clicks on it (such as Apply, Cancel, Close and Help) and when the widget is supposed to have a wide, rectangular shape with a text label. Small, typically square buttons that change the state of the window rather than performing an action (such as the buttons in the top-right corner of the TQFileDialog) are not command buttons, but tool buttons. TQt provides a special class (TQToolButton) for these buttons.

If you need toggle behavior (see setToggleButton()) or a button that auto-repeats the activation signal when being pushed down like the arrows in a scroll bar (see setAutoRepeat()), a command button is probably not what you want. When in doubt, use a tool button.

A variation of a command button is a menu button. These provide not just one command, but several, since when they are clicked they pop up a menu of options. Use the method setPopup() to associate a popup menu with a push button.

Other classes of buttons are option buttons (see TQRadioButton) and check boxes (see TQCheckBox).

In TQt, the TQButton abstract base class provides most of the modes and other API, and TQPushButton provides GUI logic. See TQButton for more information about the API.

See also TQToolButton, TQRadioButton, TQCheckBox, GUI Design Handbook: Push Button, and Basic Widgets.


Member Function Documentation

TQPushButton::TQPushButton ( TQWidget * parent, const char * name = 0 )

Constructs a push button with no text.

The parent and name arguments are sent on to the TQWidget constructor.

TQPushButton::TQPushButton ( const TQString & text, TQWidget * parent, const char * name = 0 )

Constructs a push button called name with the parent parent and the text text.

TQPushButton::TQPushButton ( const TQIconSet & icon, const TQString & text, TQWidget * parent, const char * name = 0 )

Constructs a push button with an icon and a text.

Note that you can also pass a TQPixmap object as an icon (thanks to the implicit type conversion provided by C++).

The parent and name arguments are sent to the TQWidget constructor.

TQPushButton::~TQPushButton ()

Destroys the push button.

TQKeySequence TQButton::accel () const

Returns the accelerator associated with the button. See the "accel" property for details.

bool TQPushButton::autoDefault () const

Returns TRUE if the push button is the auto default button; otherwise returns FALSE. See the "autoDefault" property for details.

bool TQButton::autoRepeat () const

Returns TRUE if autoRepeat is enabled; otherwise returns FALSE. See the "autoRepeat" property for details.

void TQButton::clicked () [signal]

This signal is emitted when the button is activated (i.e. first pressed down and then released when the mouse cursor is inside the button), when the accelerator key is typed or when animateClick() is called. This signal is not emitted if you call setDown().

The TQButtonGroup::clicked() signal does the same job, if you want to connect several buttons to the same slot.

Warning: Don't launch a model dialog in response to this signal for a button that has autoRepeat turned on.

See also pressed(), released(), toggled(), autoRepeat, and down.

Examples: chart/setdataform.cpp, listbox/listbox.cpp, network/clientserver/client/client.cpp, progressbar/progressbar.cpp, richtext/richtext.cpp, t2/main.cpp, and t4/main.cpp.

TQButtonGroup * TQButton::group () const

Returns the group that this button belongs to.

If the button is not a member of any TQButtonGroup, this function returns 0.

See also TQButtonGroup.

TQIconSet * TQPushButton::iconSet () const

Returns the icon set on the push button. See the "iconSet" property for details.

bool TQPushButton::isDefault () const

Returns TRUE if the push button is the default button; otherwise returns FALSE. See the "default" property for details.

bool TQButton::isDown () const

Returns TRUE if the button is pressed; otherwise returns FALSE. See the "down" property for details.

bool TQButton::isExclusiveToggle () const

Returns TRUE if the button is an exclusive toggle; otherwise returns FALSE. See the "exclusiveToggle" property for details.

bool TQPushButton::isFlat () const

Returns TRUE if the border is disabled; otherwise returns FALSE. See the "flat" property for details.

bool TQPushButton::isMenuButton () const

Returns TRUE if the push button has a menu button on it; otherwise returns FALSE. See the "menuButton" property for details.

bool TQButton::isOn () const

Returns TRUE if the button is toggled; otherwise returns FALSE. See the "on" property for details.

bool TQButton::isToggleButton () const

Returns TRUE if the button is a toggle button; otherwise returns FALSE. See the "toggleButton" property for details.

const TQPixmap * TQButton::pixmap () const

Returns the pixmap shown on the button. See the "pixmap" property for details.

TQPopupMenu * TQPushButton::popup () const

Returns the button's associated popup menu or 0 if no popup menu has been set.

See also setPopup().

void TQButton::pressed () [signal]

This signal is emitted when the button is pressed down.

See also released() and clicked().

Examples: network/httpd/httpd.cpp and popup/popup.cpp.

void TQButton::released () [signal]

This signal is emitted when the button is released.

See also pressed(), clicked(), and toggled().

void TQButton::setAccel ( const TQKeySequence & ) [virtual]

Sets the accelerator associated with the button. See the "accel" property for details.

void TQPushButton::setAutoDefault ( bool autoDef ) [virtual]

Sets whether the push button is the auto default button to autoDef. See the "autoDefault" property for details.

void TQButton::setAutoRepeat ( bool ) [virtual]

Sets whether autoRepeat is enabled. See the "autoRepeat" property for details.

void TQPushButton::setDefault ( bool def ) [virtual]

Sets whether the push button is the default button to def. See the "default" property for details.

void TQButton::setDown ( bool ) [virtual]

Sets whether the button is pressed. See the "down" property for details.

void TQPushButton::setFlat ( bool )

Sets whether the border is disabled. See the "flat" property for details.

void TQPushButton::setIconSet ( const TQIconSet & )

Sets the icon set on the push button. See the "iconSet" property for details.

void TQPushButton::setIsMenuButton ( bool enable ) [virtual]

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

void TQPushButton::setOn ( bool ) [virtual slot]

Sets whether the push button is toggled. See the "on" property for details.

void TQButton::setPixmap ( const TQPixmap & ) [virtual]

Sets the pixmap shown on the button. See the "pixmap" property for details.

void TQPushButton::setPopup ( TQPopupMenu * popup )

Associates the popup menu popup with this push button. This turns the button into a menu button.

Ownership of the popup menu is not transferred to the push button.

See also popup().

Examples: buttongroups/buttongroups.cpp and tqdir/tqdir.cpp.

void TQButton::setText ( const TQString & ) [virtual]

Sets the text shown on the button. See the "text" property for details.

void TQPushButton::setToggleButton ( bool )

Sets whether the button is a toggle button. See the "toggleButton" property for details.

ToggleState TQButton::state () const

Returns the state of the toggle button. See the "toggleState" property for details.

void TQButton::stateChanged ( int state ) [signal]

This signal is emitted whenever a toggle button changes state. state is On if the button is on, NoChange if it is in the "no change" state or Off if the button is off.

This may be the result of a user action, toggle() slot activation, setState(), or because setOn() was called.

See also clicked() and TQButton::ToggleState.

TQString TQButton::text () const

Returns the text shown on the button. See the "text" property for details.

void TQButton::toggle () [slot]

Toggles the state of a toggle button.

See also on, on, toggled(), and toggleButton.

void TQButton::toggled ( bool on ) [signal]

This signal is emitted whenever a toggle button changes status. on is TRUE if the button is on, or FALSE if the button is off.

This may be the result of a user action, toggle() slot activation, or because setOn() was called.

See also clicked().

Example: listbox/listbox.cpp.


Property Documentation

TQKeySequence accel

This property holds the accelerator associated with the button.

This property is 0 if there is no accelerator set. If you set this property to 0 then any current accelerator is removed.

Set this property's value with setAccel() and get this property's value with accel().

bool autoDefault

This property holds whether the push button is the auto default button.

If this property is set to TRUE then the push button is the auto default button in a dialog.

In some GUI styles a default button is drawn with an extra frame around it, up to 3 pixels or more. TQt automatically keeps this space free around auto-default buttons, i.e. auto-default buttons may have a slightly larger size hint.

This property's default is TRUE for buttons that have a TQDialog parent; otherwise it defaults to FALSE.

See the default property for details of how default and auto-default interact.

Set this property's value with setAutoDefault() and get this property's value with autoDefault().

bool autoMask

This property holds whether the button is automatically masked.

See also TQWidget::autoMask.

bool autoRepeat

This property holds whether autoRepeat is enabled.

If autoRepeat is enabled then the clicked() signal is emitted at regular intervals if the button is down. This property has no effect on toggle buttons. autoRepeat is off by default.

Set this property's value with setAutoRepeat() and get this property's value with autoRepeat().

bool default

This property holds whether the push button is the default button.

If this property is set to TRUE then the push button will be pressed if the user presses the Enter (or Return) key in a dialog.

Regardless of focus, if the user presses Enter: If there is a default button the default button is pressed; otherwise, if there are one or more autoDefault buttons the first autoDefault button that is next in the tab order is pressed. If there are no default or autoDefault buttons only pressing Space on a button with focus, mouse clicking, or using an accelerator will press a button.

In a dialog, only one push button at a time can be the default button. This button is then displayed with an additional frame (depending on the GUI style).

The default button behavior is provided only in dialogs. Buttons can always be clicked from the keyboard by pressing Enter (or Return) or the Spacebar when the button has focus.

This property's default is FALSE.

Set this property's value with setDefault() and get this property's value with isDefault().

bool flat

This property holds whether the border is disabled.

This property's default is FALSE.

Set this property's value with setFlat() and get this property's value with isFlat().

TQIconSet iconSet

This property holds the icon set on the push button.

This property will return 0 if the push button has no iconset.

Set this property's value with setIconSet() and get this property's value with iconSet().

bool menuButton

This property holds whether the push button has a menu button on it.

This property is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

If this property is set to TRUE, then a down arrow is drawn on the push button to indicate that a menu will pop up if the user clicks on the arrow.

Get this property's value with isMenuButton().

bool on

This property holds whether the push button is toggled.

This property should only be set for toggle push buttons. The default value is FALSE.

See also on, toggle(), toggled(), and toggleButton.

Set this property's value with setOn().

TQPixmap pixmap

This property holds the pixmap shown on the button.

If the pixmap is monochrome (i.e. it is a TQBitmap or its depth is 1) and it does not have a mask, this property will set the pixmap to be its own mask. The purpose of this is to draw transparent bitmaps which are important for toggle buttons, for example.

pixmap() returns 0 if no pixmap was set.

Set this property's value with setPixmap() and get this property's value with pixmap().

TQString text

This property holds the text shown on the button.

This property will return a TQString::null if the button has no text. If the text has an ampersand (&) in it, then an accelerator is automatically created for it using the character that follows the '&' as the accelerator key. Any previous accelerator will be overwritten, or cleared if no accelerator is defined by the text.

There is no default text.

Set this property's value with setText() and get this property's value with text().

bool toggleButton

This property holds whether the button is a toggle button.

Toggle buttons have an on/off state similar to check boxes. A push button is initially not a toggle button.

See also on, toggle(), toggleButton, and toggled().

Set this property's value with setToggleButton().


This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8