The next two chapters describe the two components CheckBox and RadioButton. Each component has its own specific function:
Figure 16.17.1: Three CheckBoxes and a group of three RadioButtons
Control element CheckBox
The control element CheckBox (gb.qt4) implements a CheckBox that can be selected or not. If the tristate property is defined, then the CheckBox state is interpreted as “state unknown (not defined)” or “should not be changed”.
Property | Type | Default | Description |
---|---|---|---|
Autoresize | Boolean | False | Determines the value or determines whether the size of the CheckBox automatically adapts to the descriptive text. |
Text | String | Null | Determines the text or specifies the text to be displayed on the CheckBox as caption. |
Caption | String | Null | Synonym for Text |
Tristate | Boolean | False | Determines or determines whether the CheckBox has a third state. |
Value | Integer | 0 | Determines or determines which value the CheckBox has. |
Table 16.17.1: Properties CheckBox
The property CheckBox.Value can have three values -1, 0 or 1, which applies to the state in connection with the defined CheckBox constants and the .Tristate property:
symbol | Condition | Value | Constant |
---|---|---|---|
☑ | Selected | -1 | CheckBox.True |
⎕ | Not selected | 0 | CheckBox.False |
⊟ | Indeterminate | 1 | CheckBox.None ( + CheckBox.Tristate = True) |
Table 16.17.2: Values of the property CheckBox.Value
The click event is triggered when the user clicks on the checkbox and the state of the checkbox changes. If CheckBox.Tristate = False, then the state changes alternatively. Otherwise, the order is:⎕ → ⊟ → ☑ .You can quickly convince yourself of this if you set the CheckBox.Tristate property to True or False for a CheckBox and use this event handling routine:
Public Sub CheckBox1_Click() Select CheckBox1.Value Case -1 Print "CheckBox checked" ' State: selected Case 0 Print "CheckBox unchecked" ' State: not selected Case CheckBox1.None Print "CheckBox indeterminate" ' State: indifferent End Select End ' CheckBox1_Click()
This is remarkable: The complete source code (trunk/) of gambas show an application of CheckBox.Tristate only in the supplied example GameOfLife.
In den nächsten zwei Kapiteln werden die beiden Komponenten CheckBox und RadioButton beschrieben. Jede Komponente hat ihre spezifische Funktion:
Abbildung 16.17.1: Drei CheckBoxen und eine Gruppe von drei RadioButton
Komponente CheckBox
Die Komponente CheckBox (gb.qt4) implementiert eine CheckBox, die markiert werden kann oder nicht. Wenn die Tristate-Eigenschaft festgelegt ist, dann wird der CheckBox-Zustand im Sinne von “Zustand unbekannt (nicht definiert)” oder “soll nicht geändert werden” interpretiert.
Eigenschaft | Typ | Default | Beschreibung |
---|---|---|---|
Autoresize | Boolean | False | Ermittelt den Wert oder legt fest, ob sich die Größe der CheckBox automatisch an den beschreibenden Text anpasst. |
Text | String | Null | Ermittelt den Text oder legt den Text fest, der auf der CheckBox als Beschriftung angezeigt wird. |
Caption | String | Null | Synonym für Text |
Tristate | Boolean | False | Ermittelt oder legt fest, ob die CheckBox über einen dritten Zustand verfügt. |
Value | Integer | 0 | Ermittelt oder legt fest, welchen Wert die CheckBox hat. |
Tabelle 16.17.1: Eigenschaften CheckBox
Die Eigenschaft CheckBox.Value kann drei Werte annehmen -1, 0 oder 1. Dabei gilt für den Zustand im Zusammenhang mit den definierten CheckBox-Konstanten und der .Tristate-Eigenschaft:
Symbol | Zustand | Wert | Konstante |
---|---|---|---|
☑ | Ausgewählt | -1 | CheckBox.True |
⎕ | Nicht ausgewählt | 0 | CheckBox.False |
⊟ | Unbestimmt | 1 | CheckBox.None ( + CheckBox.Tristate = True) |
Tabelle 16.17.2: Werte der Eigenschaft CheckBox.Value
Das Klick-Ereignis wird ausgelöst, wenn der Benutzer auf die CheckBox klickt und es ändert sich der Zustand der CheckBox. Gilt CheckBox.Tristate = False, dann ändert sich der Zustand alternativ. Sonst gilt die Reihenfolge: ⎕ → ⊟ → ☑ ! Davon können Sie sich selbst schnell überzeugen, wenn Sie für eine CheckBox die Eigenschaft CheckBox.Tristate auf True oder False setzen und diese Ereignisbehandlungsroutine einsetzen:
Public Sub CheckBox1_Click() Select CheckBox1.Value Case -1 Print "CheckBox checked" ' Zustand: ausgewählt Case 0 Print "CheckBox unchecked" ' Zustand: nicht ausgewählt Case CheckBox1.None Print "CheckBox indeterminate" ' Zustand: indifferent End Select End ' CheckBox1_Click()
Das ist schon bemerkenswert: Die gesamten Quelltexte (trunk/) von Gambas zeigen nur im mitgelieferten Beispiel GameOfLife eine Anwendung von CheckBox.Tristate.