User Tools

Site Tools


k16:k16.5:start

16.5 ToolButton (gb. qt4)

This class implements a button for a ToolBar. A ToolButton can display an image, a text or both. In most cases, the text is dispensed with:

toolbar&toolbutton

Figure 16.5.1: ToolButton and separators in a toolbar in the IDE

16.5.1 Properties

The properties of a ToolButton differ only slightly from the special properties of a' normal' button.

tablelayout

PropertyData typeDefaultDescription
AutoResizeBooleanFalseSpecifies whether the size of the ToolButton automatically adapts to the content (text/icon)
ActionStringNullSets the action string that is bound to the ToolButton or returns the string back
CaptionStringNullSynonym for the text property
TextStringNullSets the text to be displayed on the ToolButton or returns it back
ToogleBooleanFalseWith the value True the ToolButton has the properties of a Schalters
ValueBooleanFalseSets the value of the ToolButton as a toggle button (locked or unlocked) or returns this value
PicturePictureNull Sets the image to be displayed on the ToolButton or returns the image
ToolTipStringNullSets or returns the ToolTipö text to be displayed

Table 16.5.1.1: Selected button properties

You can use any icon on the button - it will be automatically stretched - provided that you only use ToolButton or MenuButton in the toolbar (ToolBar).

16.5.2 Events - Events

The click event is also the dominant event for a ToolButton. It is triggered when the user clicks with the mouse on the ToolButton or when the value of the. value property changes.

Section of a source code for a project in which 4 toolbuttons (→ Figure 16.5.3.1) are used:

[1] Public Sub tbImageOpen_Click()
[2]   ImageOpen()
[3]   mnu13Print.Enabled = True
[4]   tbPrint.Enabled = True
[5] End ' tbOpen_Click()
[6] 
[7] Public Sub tbImagePrint_Click()
[8]   ImageOpen()
[9]   mnu13Print.Enabled = True
[10]   tbPrint.Enabled = True
[11] End ' tbOpen_Click()
[12] 
[13] Public Sub tbHelp_Click()
[14]   FHelp.Show   
[15] End ' tbOpen_Click()
[16] 
[17] Public Sub tbFormClose_Click()
[18]   FHelp.Close
[19]   FMain.Close
[20] End ' tbOpen_Click()

16.5.3 Example

A tried and tested project for the use of a ToolBar with some ToolButtons can be found in → chapter 12.5 ToolBar. There you will find the complete source code, which is commented on in the relevant passages.

projekt

Figure 16.5.3.1: ToolButton and separators in a toolbar

Another project is described in chapter 18.6 Toolbar in connection with the properties, methods and events of the container component ToolBar.

Download

16.5 ToolButton (gb.qt4)

Diese Klasse implementiert einen Button für eine ToolBar. Ein ToolButton kann ein Bild, einen Text oder beides anzeigen. In den meisten Fällen wird auf den Text verzichtet:

toolbar&toolbutton

Abbildung 16.5.1: ToolButton und Separatoren in einer Toolbar in der IDE

16.5.1 Eigenschaften

Die Eigenschaften eines ToolButton unterscheiden sich nur wenig von den speziellen Eigenschaften eines 'normalen' Buttons.

ToolButtonDatentypDefaultBeschreibung
.AutoResizeBooleanFalseGibt an, ob sich die Größe des ToolButtons automatisch an den Inhalt (Text / Icon) anpasst
.ActionStringNullSetzt den Action-String, der an den ToolButton gebunden ist oder gibt den String zurück
.CaptionStringNullSynonym für .Text
.TextStringNullSetzt den anzuzeigenden Text auf dem ToolButton oder gibt diesen zurück
.ToogleBooleanFalseMit dem Wert True besitzt der ToolButton die Eigenschaften eines Schalters
.ValueBooleanFalseSetzt den Wert des ToolButton als ToggleButton (eingerastet oder nicht eingerastet) oder gibt diesen Wert zurück
.PicturePictureNullSetzt das anzuzeigende Bild auf dem ToolButton oder gibt das Bild zurück
.ToolTipStringNullSetzt den anzuzeigenden ToolTipp-Text des ToolButtons oder gibt diesen zurück

Tabelle 16.5.1.1: Ausgewählte Button-Eigenschaften

Sie können ein beliebiges Icon auf die Schaltfläche verwenden – es wird automatisch gestreckt werden – vorausgesetzt, dass Sie nur ToolButton oder MenuButton in der Symbolleiste (ToolBar) verwenden.

16.5.2 Ereignisse – Events

Auch bei einem ToolButton ist das Klick-Ereignis das dominante Ereignis. Es wird ausgelöst, wenn der Benutzer mit der Maus auf den ToolButton klickt oder wenn sich der Wert der Eigenschaft .Value ändert.

Ausschnitt aus einem Quelltext für ein Projekt, in dem 4 Toolbutton (→ Abbildung 16.5.3.1) verwendet werden:

[1] Public Sub tbImageOpen_Click()
[2]   ImageOpen()
[3]   mnu13Print.Enabled = True
[4]   tbPrint.Enabled = True
[5] End ' tbOpen_Click()
[6] 
[7] Public Sub tbImagePrint_Click()
[8]   ImageOpen()
[9]   mnu13Print.Enabled = True
[10]   tbPrint.Enabled = True
[11] End ' tbOpen_Click()
[12] 
[13] Public Sub tbHelp_Click()
[14]   FHelp.Show   
[15] End ' tbOpen_Click()
[16] 
[17] Public Sub tbFormClose_Click()
[18]   FHelp.Close
[19]   FMain.Close
[20] End ' tbOpen_Click()

16.5.3 Beispiel

Ein erprobtes Projekt für den Einsatz einer ToolBar mit einigen ToolButton finden Sie im Kapitel 12.5. ToolBar. Dort finden Sie den kompletten Quelltext, der in den relevanten Passagen kommentiert wird.

projekt

Abbildung 16.5.3.1: ToolButton und Separatoren in einer Toolbar

Ein weiteres Projekt wird im Kapitel 18.6 Toolbar im Zusammenhang mit den Eigenschaften, Methoden und Ereignissen der Container-Komponente ToolBar beschrieben.

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k16/k16.5/start.txt · Last modified: 02.07.2018 (external edit)

Page Tools