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

TQButton Class Reference

The TQButton class is the abstract base class of button widgets, providing functionality common to buttons. More...

#include <qbutton.h>

Inherits TQWidget.

Inherited by TQCheckBox, TQPushButton, TQRadioButton, and TQToolButton.

List of all member functions.

Public Members

Public Slots

Signals

Properties

Protected Members


Detailed Description

The TQButton class is the abstract base class of button widgets, providing functionality common to buttons.

If you want to create a button use TQPushButton.

The TQButton class implements an abstract button, and lets subclasses specify how to reply to user actions and how to draw the button.

TQButton provides both push and toggle buttons. The TQRadioButton and TQCheckBox classes provide only toggle buttons; TQPushButton and TQToolButton provide both toggle and push buttons.

Any button can have either a text or pixmap label. setText() sets the button to be a text button and setPixmap() sets it to be a pixmap button. The text/pixmap is manipulated as necessary to create the "disabled" appearance when the button is disabled.

TQButton provides most of the states used for buttons:

The difference between isDown() and isOn() is as follows: When the user clicks a toggle button to toggle it on, the button is first pressed and then released into the on state. When the user clicks it again (to toggle it off), the button moves first to the pressed state, then to the off state (isOn() and isDown() are both FALSE).

Default buttons (as used in many dialogs) are provided by TQPushButton::setDefault() and TQPushButton::setAutoDefault().

TQButton provides five signals:

  1. pressed() is emitted when the button is pressed. E.g. with the mouse or when animateClick() is called.
  2. released() is emitted when the button is released. E.g. when the mouse is released or the cursor is moved outside the widget.
  3. clicked() is emitted when the button is first pressed and then released when the accelerator key is typed, or when animateClick() is called.
  4. toggled(bool) is emitted when the state of a toggle button changes.
  5. stateChanged(int) is emitted when the state of a tristate toggle button changes.

If the button is a text button with an ampersand (&) in its text, TQButton creates an automatic accelerator key. This code creates a push button labelled "Rock & Roll" (where the c is underlined). The button gets an automatic accelerator key, Alt+C:

        TQPushButton *p = new TQPushButton( "Ro&ck && Roll", this );
    

In this example, when the user presses Alt+C the button will call animateClick().

You can also set a custom accelerator using the setAccel() function. This is useful mostly for pixmap buttons because they have no automatic accelerator.

        p->setPixmap( TQPixmap("print.png") );
        p->setAccel( ALT+Key_F7 );
    

All of the buttons provided by TQt (TQPushButton, TQToolButton, TQCheckBox and TQRadioButton) can display both text and pixmaps.

To subclass TQButton, you must reimplement at least drawButton() (to draw the button's outline) and drawButtonLabel() (to draw its text or pixmap). It is generally advisable to reimplement sizeHint() as well, and sometimes hitButton() (to determine whether a button press is within the button).

To reduce flickering, TQButton::paintEvent() sets up a pixmap that the drawButton() function draws in. You should not reimplement paintEvent() for a subclass of TQButton unless you want to take over all drawing.

See also TQButtonGroup and Abstract Widget Classes.


Member Type Documentation

TQButton::ToggleState

This enum defines the state of a toggle button.

TQButton::ToggleType

This enum type defines what a button can do in response to a mouse/keyboard press:


Member Function Documentation

TQButton::TQButton ( TQWidget * parent = 0, const char * name = 0, WFlags f = 0 )

Constructs a standard button called name with parent parent, using the widget flags f.

If parent is a TQButtonGroup, this constructor calls TQButtonGroup::insert().

TQButton::~TQButton ()

Destroys the button.

TQKeySequence TQButton::accel () const

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

void TQButton::animateClick () [slot]

Performs an animated click: the button is pressed and released a short while later.

The pressed(), released(), clicked(), toggled(), and stateChanged() signals are emitted as appropriate.

This function does nothing if the button is disabled.

See also accel.

bool TQButton::autoRepeat () const

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

bool TQButton::autoResize () const

Returns TRUE if autoResize is enabled; otherwise returns FALSE. See the "autoResize" 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.

void TQButton::drawButton ( TQPainter * ) [virtual protected]

Draws the button. The default implementation does nothing.

This virtual function is reimplemented by subclasses to draw real buttons. At some point, these reimplementations should call drawButtonLabel().

See also drawButtonLabel() and paintEvent().

void TQButton::drawButtonLabel ( TQPainter * ) [virtual protected]

Draws the button text or pixmap.

This virtual function is reimplemented by subclasses to draw real buttons. It is invoked by drawButton().

See also drawButton() and paintEvent().

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.

bool TQButton::hitButton ( const TQPoint & pos ) const [virtual protected]

Returns TRUE if pos is inside the clickable button rectangle; otherwise returns FALSE.

By default, the clickable area is the entire widget. Subclasses may reimplement it, though.

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 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.

void TQButton::paintEvent ( TQPaintEvent * ) [virtual protected]

Handles paint events for buttons. Small and typically complex buttons are painted double-buffered to reduce flicker. The actually drawing is done in the virtual functions drawButton() and drawButtonLabel().

See also drawButton() and drawButtonLabel().

Reimplemented from TQWidget.

const TQPixmap * TQButton::pixmap () const

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

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 TQButton::setAutoRepeat ( bool ) [virtual]

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

void TQButton::setAutoResize ( bool )

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

void TQButton::setDown ( bool ) [virtual]

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

void TQButton::setOn ( bool on ) [protected]

Sets the state of this button to On if on is TRUE; otherwise to Off.

See also toggleState.

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

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

void TQButton::setState ( ToggleState s ) [virtual protected]

Sets the toggle state of the button to s. s can be Off, NoChange or On.

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

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

void TQButton::setToggleButton ( bool b ) [protected]

If b is TRUE, this button becomes a toggle button; if b is FALSE, this button becomes a command button.

See also toggleButton.

void TQButton::setToggleType ( ToggleType type ) [virtual protected]

Sets the toggle type of the button to type.

type can be set to SingleShot, Toggle and Tristate.

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, setOn(), toggled(), and toggleButton.

ToggleType TQButton::toggleType () const

Returns the type of toggle on the button. See the "toggleType" property for details.

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 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 autoResize

This property holds whether autoResize is enabled.

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

If autoResize is enabled then the button will resize itself whenever the contents are changed.

Set this property's value with setAutoResize() and get this property's value with autoResize().

bool down

This property holds whether the button is pressed.

If this property is TRUE, the button is pressed down. The signals pressed() and clicked() are not emitted if you set this property to TRUE. The default is FALSE.

Set this property's value with setDown() and get this property's value with isDown().

bool exclusiveToggle

This property holds whether the button is an exclusive toggle.

If this property is TRUE and the button is in a TQButtonGroup, the button can only be toggled off by another one being toggled on. The default is FALSE.

Get this property's value with isExclusiveToggle().

bool on

This property holds whether the button is toggled.

This property should only be set for toggle buttons.

Get this property's value with isOn().

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.

The default value is FALSE.

Get this property's value with isToggleButton().

ToggleState toggleState

This property holds the state of the toggle button.

If this property is changed then it does not cause the button to be repainted.

Get this property's value with state().

ToggleType toggleType

This property holds the type of toggle on the button.

The default toggle type is SingleShot.

See also TQButton::ToggleType.

Get this property's value with toggleType().


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


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8