ホーム · All Namespaces · 全てのクラス · メインのクラス · グループ別 · Modules · 関数一覧

QPushButton Class Reference
[QtGui module]

QPushButtonはコマンドボタンを提供します。 More...

 #include <QPushButton>

Inherits QAbstractButton.

継承元 QCommandLinkButton.

Properties

Public Functions

Public Slots

Protected Functions

Additional Inherited Members


詳細

QPushButtonはコマンドボタンを提供します。

プッシュボタン、コマンドボタンは多くのGUIで用いられる一般的なウィジェットです。コンピュータに何らかのアクションをさせるために、ボタンをプッシュ(クリック)します。代表的なボタンは「OK」「Apply」「Cancel」「Close」「Yes」「No」「Help」です。

コマンドボタンは通常、動作を説明するテキストラベルと共に使用する長方形のボタンです。「&」記号をテキストの前に付けることによりショートカットを指定できます。

 QPushButton *button = new QPushButton("&Download", this);

この例でのショートカットは Alt+Dです。詳しくは QShortcut のドキュメントを見てください。(ディスプレイ上に「&」を表示したい場合は「&&」としてください。)

プッシュボタンの表示にはテキストラベルと小さなアイコンが使用できます。これらはコンストラクタで設定でき、後で setText() と setIcon() で設定できます。ボタンが無効な場合、GUIによりボタンのアイコンが無効な状態となります。

プッシュボタンはマウスやショートカットによって clicked()シグナルを送ります。このシグナルをボタンのアクションに接続してください。またプッシュボタンは一般的なシグナルも提供します。例えば pressed() と released()です。

ダイアログ内のコマンドボタンは自動的にデフォルトになります。キーボードからフォーカスを受け取った時、自動的にデフォルトのプッシュボタンとなります。デフォルトボタンはユーザがダイアログ内でEnterまたはReturnキーを押した時に作動するボタンです。これは setAutoDefault()を使い変更することができます。auto-defaultボタンはデフォルトボタンを描画するために少し余白が確保されることに注意してください。もし余白が必要ないなら、setAutoDefault(false)を使用してください。

重要なことは、ボタンウィジェットは過去10年間で大きな変化を遂げてきました。マイクロソフトではよそ10種類の異なるボタンを提供しています。そして、テキストは特徴のすべてを考慮するとさらに数十種類は存在します。

重要なモードと状態:

一般的に、アプリケーションかダイアログウィンドウを実行する時、ユーザがこれら(「Apply」や「Cancel」等)をクリックする時、またウィジェットがテキストラベルを持つ時にプッシュボタンを使用します。 when the widget is supposed to have a wide, rectangular shape with a text label. 行動(例えば QFileDialogの右上隅のボタン)を実行することよりも、むしろウィンドウの形を変えるために用いる、小さな典型的なボタンはコマンドボタンではなくツールボタンです。Qtは特別なクラスを提供しています(QToolButtonこれらのボタンです)

もしトグル動作が必要なら setCheckable()か 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 setMenu() to associate a popup menu with a push button.

Other classes of buttons are option buttons (see QRadioButton) and check boxes (see QCheckBox).

A push button shown in the Macintosh widget style.

Note that when a button's width becomes smaller than 50 or its height becomes smaller than 30, the button's corners are changed from round to square. Use the setMinimumSize() function to prevent this behavior.

A push button shown in the Windows XP widget style.
A push button shown in the Plastique widget style.

In Qt, the QAbstractButton base class provides most of the modes and other API, and QPushButton provides GUI logic. See QAbstractButton for more information about the API.

See also QToolButton, QRadioButton, QCheckBox, and GUI Design Handbook: Push Button.


Property Documentation

autoDefault : bool

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

If this property is set to true then the push button is an auto default button.

In some GUI styles a default button is drawn with an extra frame around it, up to 3 pixels or more. Qt 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 QDialog parent; otherwise it defaults to false.

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

Access functions:

default : bool

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

Default and autodefault buttons decide what happens when the user presses enter in a dialog.

A button with this property set to true (i.e., the dialog's default button,) will automatically be pressed when the user presses enter, with one exception: if an autoDefault button currently has focus, the autoDefault button is pressed. When the dialog has autoDefault buttons but no default button, pressing enter will press either the autoDefault button that currently has focus, or if no button has focus, the next autoDefault button in the focus chain.

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 Spacebar when the button has focus.

If the default property is set to false on the current default button while the dialog is visible, a new default will automatically be assigned the next time a pushbutton in the dialog receives focus.

This property's default is false.

Access functions:

flat : bool

This property holds whether the button border is raised.

This property's default is false. If this property is set, most styles will not paint the button background unless the button is being pressed. setAutoFillBackground() can be used to ensure that the background is filled using the QPalette::Button brush.

Access functions:


Member Function Documentation

QPushButton::QPushButton ( QWidget * parent = 0 )

Constructs a push button with no text and a parent.

QPushButton::QPushButton ( const QString & text, QWidget * parent = 0 )

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

QPushButton::QPushButton ( const QIcon & icon, const QString & text, QWidget * parent = 0 )

Constructs a push button with an icon and a text, and a parent.

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

QPushButton::~QPushButton ()

Destroys the push button.

void QPushButton::initStyleOption ( QStyleOptionButton * option ) const   [protected]

Initialize option with the values from this QPushButton. This method is useful for subclasses when they need a QStyleOptionButton, but don't want to fill in all the information themselves.

See also QStyleOption::initFrom().

QMenu * QPushButton::menu () const

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

See also setMenu().

void QPushButton::setMenu ( QMenu * menu )

Associates the popup menu menu with this push button. This turns the button into a menu button, which in some styles will produce a small triangle to the right of the button's text.

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

Push buttons with popup menus shown in the Plastique widget style (left) and Cleanlooks widget style (right).

See also menu().

void QPushButton::showMenu ()   [slot]

Shows (pops up) the associated popup menu. If there is no such menu, this function does nothing. This function does not return until the popup menu has been closed by the user.


Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt 4.5.0