User Tools

Site Tools


CommandButton (QPushButton)


The Qt documentation in C++ of this class can be read here:

A control for the form object, provides a push button.

The command button, or push button, is perhaps the most commonly used control 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. Command buttons can display a textual label or an icon.

Most important

Methods None
Properties Icon , Caption
Events OnEvent

Please read the control class overview Control as well.



Property AutoDefault As Boolean (ReadWrite)


Property Default As Boolean (ReadWrite)

This property holds whether the CommandButton is the default button.

If it is to true then the CommandButton 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 default button behavior is provided only in dialogs. Buttons can always be clicked from the keyboard by pressing Spacebar when the button has focus.


Property Checkable As Boolean (ReadWrite)

If it is true, the CommandButton appears as checkable button. If you would like to group several buttons as auto-exclusive group, set for all buttons the same group name.


Property Checked As Boolean (ReadWrite)

If it is true, the CommandButton is checked.


Property Flat As Boolean (ReadWrite)

If it is true, the CommandButton appears as flat button. This is only useful to change the visual appearance.


Property Icon As String (ReadWrite)

Either an icon or caption is visible on a CommandButton. If you set an icon, the caption will not be displayed. An icon can be an absolute path to an image file (png, jpg,…) like c:\myfolder\myimage.png or can be an relative path to the current project like myimage.png (which is present in the current project directory). Relative paths are recommended.

Might be a String containing binary data. See the binary project example for using.


Dim c As CommandButton
c = Control("Button1") ' Button1 is declared as CommandButton in this form
c.Icon= "tux.jpg" ' relative path. File exists in current project directory

See also Caption


Property Key As String (ReadWrite)

Holds the information, which key press would raise the event connected to this CommandButton, e.g. Ctrl+O. The strings “Ctrl”, “Shift”, “Alt” and “Meta” are recognized.




Default keys are

HelpContentsOpen help contents
WhatsThisActivate whats this.
OpenOpen Document.
CloseClose Document/Tab.
SaveSave Document.
NewCreate new Document.
BackNavigate back.
ForwardNavigate forward.
RefreshRefresh or reload current document.
ZoomInZoom in.
ZoomOutZoom out.
PrintPrint document.
AddTabAdd new tab.
NextChildNavigate to next tab or child window.
PreviousChildNavigate to previous tab or child window.
FindFind in document.
FindNextFind next result.
FindPreviousFind previous result.
ReplaceFind and replace.
SelectAllSelect all text.
BoldBold text.
ItalicItalic text.
UnderlineUnderline text.
MoveToNextCharMove cursor to next character.
MoveToPreviousCharMove cursor to previous character.
MoveToNextWordMove cursor to next word.
MoveToPreviousWordMove cursor to previous word.
MoveToNextLineMove cursor to next line.
MoveToPreviousLineMove cursor to previous line.
MoveToNextPageMove cursor to next page.
MoveToPreviousPageMove cursor to previous page.
MoveToStartOfLineMove cursor to start of line.
MoveToEndOfLineMove cursor to end of line.
MoveToStartOfBlockMove cursor to start of a block. This shortcut is only used on OS X.
MoveToEndOfBlockMove cursor to end of block. This shortcut is only used on the OS X.
MoveToStartOfDocumentMove cursor to start of document.
MoveToEndOfDocumentMove cursor to end of document.
SelectNextCharExtend selection to next character.
SelectPreviousCharExtend selection to previous character.
SelectNextWordExtend selection to next word.
SelectPreviousWordExtend selection to previous word.
SelectNextLineExtend selection to next line.
SelectPreviousLineExtend selection to previous line.
SelectNextPageExtend selection to next page.
SelectPreviousPageExtend selection to previous page.
SelectStartOfLineExtend selection to start of line.
SelectEndOfLineExtend selection to end of line.
SelectStartOfBlockExtend selection to the start of a text block. This shortcut is only used on OS X.
SelectEndOfBlockExtend selection to the end of a text block. This shortcut is only used on OS X.
SelectStartOfDocumentExtend selection to start of document.
SelectEndOfDocumentExtend selection to end of document.
DeleteStartOfWordDelete the beginning of a word up to the cursor.
DeleteEndOfWordDelete word from the end of the cursor.


Property Caption As String (ReadWrite)

Holds the text to be displayed on the CommandButton.


Dim c As CommandButton
c = FormControl("Button1") ' Button1 is declared as CommandButton in this form
c.Caption = "Hello World!"

If you want the commandbutton to respond to key inputs, set the property Key. The character ”&” is used to underline the key the next character. Double ”&&” shows one ”&” in the caption.

See also Icon


Property Text As String (ReadWrite)

Same as Caption. Provided for easy-use.


Property Value As String (ReadWrite)

Same as Caption. Provided for easy-use.

Not implemented yet:

AutoRepeat ( bool ) AutoRepeatDelay ( int ) AutoRepeatInterval ( int )



Sub OnEvent()

This event is raised, whenever the user presses the CommandButton, either by mouse or key.


Sub Button1_OnEvent()
  Print "Button1 pressed"
End Sub

commandbutton.txt · Last modified: 2013/04/09 22:57 (external edit)