|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QWidget
com.trolltech.qt.gui.QAbstractButton
com.trolltech.qt.gui.QCheckBox
public class QCheckBox
The QCheckBox widget provides a checkbox with a text label.
A QCheckBox is an option button that can be switched on (checked) or off (unchecked). Checkboxes are typically used to represent features in an application that can be enabled or disabled without affecting others, but different types of behavior can be implemented.
A QButtonGroup can be used to group check buttons visually.
Whenever a checkbox is checked or cleared it emits the signal stateChanged. Connect to this signal if you want to trigger an action each time the checkbox changes state. You can use isChecked to query whether or not a checkbox is checked.
In addition to the usual checked and unchecked states, QCheckBox optionally provides a third state to indicate "no change". This is useful whenever you need to give the user the option of neither checking nor unchecking a checkbox. If you need this third state, enable it with setTristate, and use checkState to query the current toggle state.
Just like QPushButton, a checkbox displays text, and optionally a small icon. The icon is set with setIcon. The text can be set in the constructor or with setText. A shortcut key can be specified by preceding the preferred character with an ampersand. For example:
QCheckBox *checkbox = new QCheckBox("C&ase sensitive", this);
In this example the shortcut is Alt+A. See the QShortcut documentation for details (to display an actual ampersand, use '&&').
Important inherited functions: text, setText, text, pixmap, setPixmap(), accel(), setAccel(), isToggleButton(), setDown, isDown, isOn(), checkState, autoRepeat, isExclusiveToggle(), group, setAutoRepeat, toggle, pressed, released, clicked, toggled, checkState, and stateChanged.
![]() | A checkbox shown in the Macintosh widget style. |
![]() | A checkbox shown in the Windows XP widget style. |
![]() | A checkbox shown in the Plastique widget style. |
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget |
---|
QWidget.RenderFlag, QWidget.RenderFlags |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I> |
Field Summary | |
---|---|
QSignalEmitter.Signal1<java.lang.Integer> |
stateChanged
This signal is emitted whenever the check box's state changes, i.e. whenever the user checks or unchecks it. |
Fields inherited from class com.trolltech.qt.gui.QAbstractButton |
---|
clicked, pressed, released, toggled |
Fields inherited from class com.trolltech.qt.gui.QWidget |
---|
customContextMenuRequested |
Constructor Summary | |
---|---|
QCheckBox()
Equivalent to QCheckBox(0). |
|
QCheckBox(QWidget parent)
Constructs a checkbox with the given parent, but with no text. |
|
QCheckBox(java.lang.String text)
Equivalent to QCheckBox(text, 0). |
|
QCheckBox(java.lang.String text,
QWidget parent)
Constructs a checkbox with the given parent and text. |
Method Summary | |
---|---|
Qt.CheckState |
checkState()
Returns the check box's check state. |
protected void |
checkStateSet()
This virtual handler is called when setChecked was called, unless it was called from within nextCheckState. |
boolean |
event(QEvent e)
This is the main event handler; it handles event arg__1. You can reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead. Key press and release events are treated differently from other events. event checks for Tab and Shift+Tab and tries to move the focus appropriately. If there is no widget to move the focus to (or the key press is not Tab or Shift+Tab), event calls keyPressEvent. Mouse and tablet event handling is also slightly special: only when the widget is enabled, event will call the specialized handlers such as mousePressEvent; otherwise it will discard the event. This function returns true if the event was recognized, otherwise it returns false. If the recognized event was accepted (see QEvent::accepted), any further processing such as event propagation to the parent widget stops. |
static QCheckBox |
fromNativePointer(QNativePointer nativePointer)
This function returns the QCheckBox instance pointed to by nativePointer |
protected boolean |
hitButton(QPoint pos)
Returns true if pos is inside the clickable button rectangle; otherwise returns false. |
protected void |
initStyleOption(QStyleOptionButton option)
Initialize option with the values from this QCheckBox. |
boolean |
isTristate()
Returns whether the checkbox is a tri-state checkbox. |
protected void |
mouseMoveEvent(QMouseEvent arg__1)
This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse move events for the widget. If mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed. QMouseEvent::pos() reports the position of the mouse cursor, relative to this widget. For press and release events, the position is usually the same as the position of the last mouse move event, but it might be different if the user's hand shakes. This is a feature of the underlying window system, not Qt. |
protected void |
nextCheckState()
This virtual handler is called when a button is clicked. |
protected void |
paintEvent(QPaintEvent arg__1)
This event handler can be reimplemented in a subclass to receive paint events which are passed in the arg__1 parameter. A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint or update, or because the widget was obscured and has now been uncovered, or for many other reasons. Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example. Qt also tries to speed up painting by merging multiple paint events into one. When update is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint does not permit this optimization, so we suggest using update whenever possible. When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background. The background can be set using setBackgroundRole and setPalette. From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent to avoid flicker. Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage: ... extern void qt_x11_set_global_double_buffer(bool); qt_x11_set_global_double_buffer(false); ... Note: In general, one should refrain from calling update or repaint inside of paintEvent. For example, calling update or repaint on children inside a paintEvent results in undefined behavior; the child may or may not get a paint event. |
void |
setCheckState(Qt.CheckState state)
Sets the check box's check state to state. |
void |
setTristate()
Equivalent to setTristate(true). |
void |
setTristate(boolean y)
Sets whether the checkbox is a tri-state checkbox to y. |
QSize |
sizeHint()
Returns the recommended size for the widget. |
Methods inherited from class com.trolltech.qt.gui.QAbstractButton |
---|
animateClick, animateClick, autoExclusive, autoRepeat, autoRepeatDelay, autoRepeatInterval, changeEvent, click, focusInEvent, focusOutEvent, group, icon, iconSize, isCheckable, isChecked, isDown, keyPressEvent, keyReleaseEvent, mousePressEvent, mouseReleaseEvent, setAutoExclusive, setAutoRepeat, setAutoRepeatDelay, setAutoRepeatInterval, setCheckable, setChecked, setDown, setIcon, setIconSize, setShortcut, setShortcut, setShortcut, setText, shortcut, text, timerEvent, toggle |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
disconnect, disconnect, signalSender |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Field Detail |
---|
public final QSignalEmitter.Signal1<java.lang.Integer> stateChanged
This signal is emitted whenever the check box's state changes, i.e. whenever the user checks or unchecks it.
arg__1 contains the check box's new ToggleState.
Constructor Detail |
---|
public QCheckBox()
Equivalent to QCheckBox(0).
public QCheckBox(QWidget parent)
Constructs a checkbox with the given parent, but with no text.
The parent argument is passed on to the QAbstractButton constructor.
public QCheckBox(java.lang.String text)
Equivalent to QCheckBox(text, 0).
public QCheckBox(java.lang.String text, QWidget parent)
Constructs a checkbox with the given parent and text.
The parent argument is passed on to the QAbstractButton constructor.
Method Detail |
---|
public final Qt.CheckState checkState()
Returns the check box's check state.
public final boolean isTristate()
Returns whether the checkbox is a tri-state checkbox.
The default is false; i.e. the checkbox has only two states.
public final void setCheckState(Qt.CheckState state)
Sets the check box's check state to state.
public final void setTristate()
Equivalent to setTristate(true).
public final void setTristate(boolean y)
Sets whether the checkbox is a tri-state checkbox to y.
The default is false; i.e. the checkbox has only two states.
protected void checkStateSet()
This virtual handler is called when setChecked was called, unless it was called from within nextCheckState. It allows subclasses to reset their intermediate button states.
checkStateSet
in class QAbstractButton
public boolean event(QEvent e)
This is the main event handler; it handles event arg__1. You can reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead.
Key press and release events are treated differently from other events. event checks for Tab and Shift+Tab and tries to move the focus appropriately. If there is no widget to move the focus to (or the key press is not Tab or Shift+Tab), event calls keyPressEvent.
Mouse and tablet event handling is also slightly special: only when the widget is enabled, event will call the specialized handlers such as mousePressEvent; otherwise it will discard the event.
This function returns true if the event was recognized, otherwise it returns false. If the recognized event was accepted (see QEvent::accepted), any further processing such as event propagation to the parent widget stops.
event
in class QAbstractButton
protected boolean hitButton(QPoint pos)
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 this function to provide support for clickable areas of different shapes and sizes.
hitButton
in class QAbstractButton
protected void mouseMoveEvent(QMouseEvent arg__1)
This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse move events for the widget.
If mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed.
QMouseEvent::pos() reports the position of the mouse cursor, relative to this widget. For press and release events, the position is usually the same as the position of the last mouse move event, but it might be different if the user's hand shakes. This is a feature of the underlying window system, not Qt.
mouseMoveEvent
in class QAbstractButton
Example
protected void nextCheckState()
This virtual handler is called when a button is clicked. The default implementation calls setChecked(!isChecked) if the button isCheckable. It allows subclasses to implement intermediate button states.
nextCheckState
in class QAbstractButton
protected void paintEvent(QPaintEvent arg__1)
This event handler can be reimplemented in a subclass to receive paint events which are passed in the arg__1 parameter.
A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint or update, or because the widget was obscured and has now been uncovered, or for many other reasons.
Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.
Qt also tries to speed up painting by merging multiple paint events into one. When update is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint does not permit this optimization, so we suggest using update whenever possible.
When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.
The background can be set using setBackgroundRole and setPalette.
From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent to avoid flicker.
Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:
... extern void qt_x11_set_global_double_buffer(bool); qt_x11_set_global_double_buffer(false); ...
Note: In general, one should refrain from calling update or repaint inside of paintEvent. For example, calling update or repaint on children inside a paintEvent results in undefined behavior; the child may or may not get a paint event.
paintEvent
in class QAbstractButton
public QSize sizeHint()
Returns the recommended size for the widget.
If the value of this property is an invalid size, no size is recommended.
The default implementation of sizeHint returns an invalid size if there is no layout for this widget, and returns the layout's preferred size otherwise.
sizeHint
in class QWidget
public static QCheckBox fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.protected final void initStyleOption(QStyleOptionButton option)
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |