com.trolltech.qt.gui
Class QCheckBox

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.gui.QWidget
                  extended by com.trolltech.qt.gui.QAbstractButton
                      extended by com.trolltech.qt.gui.QCheckBox
All Implemented Interfaces:
QPaintDeviceInterface, QtJambiInterface

public class QCheckBox
extends QAbstractButton

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.

Screenshot of a Macintosh style checkboxA checkbox shown in the Macintosh widget style.
Screenshot of a Windows XP style checkboxA checkbox shown in the Windows XP widget style.
Screenshot of a Plastique style checkboxA checkbox shown in the Plastique widget style.

See Also:
QAbstractButton, QRadioButton, GUI Design Handbook: Check Box

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 function is reimplemented for internal reasons.
 boolean event(QEvent e)
          This function is reimplemented for internal reasons.
static QCheckBox fromNativePointer(QNativePointer nativePointer)
          This function returns the QCheckBox instance pointed to by nativePointer
protected  boolean hitButton(QPoint pos)
          This function is reimplemented for internal reasons.
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 function is reimplemented for internal reasons.
protected  void nextCheckState()
          This function is reimplemented for internal reasons.
protected  void paintEvent(QPaintEvent arg__1)
          This function is reimplemented for internal reasons.
 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()
          This function is reimplemented for internal reasons.
 
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.gui.QWidget
acceptDrops, accessibleDescription, accessibleName, actionEvent, actions, activateWindow, addAction, addActions, adjustSize, autoFillBackground, backgroundRole, baseSize, childAt, childAt, childrenRect, childrenRegion, clearFocus, clearMask, close, closeEvent, contentsRect, contextMenuEvent, contextMenuPolicy, createWinId, cursor, depth, destroy, destroy, destroy, devType, dragEnterEvent, dragLeaveEvent, dragMoveEvent, dropEvent, ensurePolished, enterEvent, focusNextChild, focusNextPrevChild, focusPolicy, focusPreviousChild, focusProxy, focusWidget, font, fontInfo, fontMetrics, foregroundRole, frameGeometry, frameSize, geometry, getContentsMargins, grabKeyboard, grabMouse, grabMouse, grabShortcut, grabShortcut, hasFocus, hasMouseTracking, height, heightForWidth, heightMM, hide, hideEvent, inputContext, inputMethodEvent, inputMethodQuery, insertAction, insertActions, isActiveWindow, isAncestorOf, isEnabled, isEnabledTo, isFullScreen, isHidden, isLeftToRight, isMaximized, isMinimized, isModal, isRightToLeft, isVisible, isVisibleTo, isWindow, isWindowModified, keyboardGrabber, layout, layoutDirection, leaveEvent, locale, logicalDpiX, logicalDpiY, lower, mapFrom, mapFromGlobal, mapFromParent, mapTo, mapToGlobal, mapToParent, mask, maximumHeight, maximumSize, maximumWidth, metric, minimumHeight, minimumSize, minimumSizeHint, minimumWidth, mouseDoubleClickEvent, mouseGrabber, move, move, moveEvent, nextInFocusChain, normalGeometry, numColors, overrideWindowFlags, overrideWindowFlags, overrideWindowState, overrideWindowState, paintEngine, paintingActive, palette, parentWidget, physicalDpiX, physicalDpiY, pos, raise, rect, releaseKeyboard, releaseMouse, releaseShortcut, removeAction, render, render, render, render, render, repaint, repaint, repaint, repaint, resetInputContext, resize, resize, resizeEvent, restoreGeometry, saveGeometry, scroll, scroll, setAcceptDrops, setAccessibleDescription, setAccessibleName, setAttribute, setAttribute, setAutoFillBackground, setBackgroundRole, setBaseSize, setBaseSize, setContentsMargins, setContentsMargins, setContextMenuPolicy, setCursor, setDisabled, setEnabled, setFixedHeight, setFixedSize, setFixedSize, setFixedWidth, setFocus, setFocus, setFocusPolicy, setFocusProxy, setFont, setForegroundRole, setGeometry, setGeometry, setHidden, setInputContext, setLayout, setLayoutDirection, setLocale, setMask, setMask, setMaximumHeight, setMaximumSize, setMaximumSize, setMaximumWidth, setMinimumHeight, setMinimumSize, setMinimumSize, setMinimumWidth, setMouseTracking, setPalette, setParent, setParent, setParent, setShortcutAutoRepeat, setShortcutAutoRepeat, setShortcutEnabled, setShortcutEnabled, setSizeIncrement, setSizeIncrement, setSizePolicy, setSizePolicy, setStatusTip, setStyle, setStyleSheet, setTabOrder, setToolTip, setUpdatesEnabled, setVisible, setWhatsThis, setWindowFlags, setWindowFlags, setWindowIcon, setWindowIconText, setWindowModality, setWindowModified, setWindowOpacity, setWindowRole, setWindowState, setWindowState, setWindowTitle, show, showEvent, showFullScreen, showMaximized, showMinimized, showNormal, size, sizeIncrement, sizePolicy, stackUnder, statusTip, style, styleSheet, tabletEvent, testAttribute, toolTip, underMouse, unsetCursor, unsetLayoutDirection, unsetLocale, update, update, update, update, updateGeometry, updateMicroFocus, updatesEnabled, visibleRegion, whatsThis, wheelEvent, width, widthMM, window, windowFlags, windowIcon, windowIconText, windowModality, windowOpacity, windowRole, windowState, windowTitle, windowType, winId, x, y
 
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

stateChanged

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.

Compatible Slot Signatures:
void mySlot(int arg__1)
void mySlot()

Constructor Detail

QCheckBox

public QCheckBox()

Equivalent to QCheckBox(0).


QCheckBox

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.


QCheckBox

public QCheckBox(java.lang.String text)

Equivalent to QCheckBox(text, 0).


QCheckBox

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

checkState

public final Qt.CheckState checkState()

Returns the check box's check state.

See Also:
setCheckState, Qt::CheckState

isTristate

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.


setCheckState

public final void setCheckState(Qt.CheckState state)

Sets the check box's check state to state.

See Also:
checkState, Qt::CheckState

setTristate

public final void setTristate()

Equivalent to setTristate(true).


setTristate

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.

See Also:
isTristate

checkStateSet

protected void checkStateSet()

This function is reimplemented for internal reasons.

Overrides:
checkStateSet in class QAbstractButton
See Also:
nextCheckState

event

public boolean event(QEvent e)

This function is reimplemented for internal reasons.

Overrides:
event in class QAbstractButton
See Also:
closeEvent, focusInEvent, focusOutEvent, enterEvent, keyPressEvent, keyReleaseEvent, leaveEvent, mouseDoubleClickEvent, mouseMoveEvent, mousePressEvent, mouseReleaseEvent, moveEvent, paintEvent, resizeEvent, QObject::event, QObject::timerEvent

hitButton

protected boolean hitButton(QPoint pos)

This function is reimplemented for internal reasons.

Overrides:
hitButton in class QAbstractButton

mouseMoveEvent

protected void mouseMoveEvent(QMouseEvent arg__1)

This function is reimplemented for internal reasons.

Overrides:
mouseMoveEvent in class QAbstractButton
See Also:
setMouseTracking, mousePressEvent, mouseReleaseEvent, mouseDoubleClickEvent, event, QMouseEvent, Example

nextCheckState

protected void nextCheckState()

This function is reimplemented for internal reasons.

Overrides:
nextCheckState in class QAbstractButton
See Also:
checkStateSet

paintEvent

protected void paintEvent(QPaintEvent arg__1)

This function is reimplemented for internal reasons.

Specified by:
paintEvent in class QAbstractButton
See Also:
event, repaint, update, QPainter, QPixmap, QPaintEvent, Analog Clock Example

sizeHint

public QSize sizeHint()

This function is reimplemented for internal reasons.

Overrides:
sizeHint in class QWidget
See Also:
QSize::isValid, minimumSizeHint, sizePolicy, setMinimumSize, updateGeometry

fromNativePointer

public static QCheckBox fromNativePointer(QNativePointer nativePointer)
This function returns the QCheckBox instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

initStyleOption

protected final void initStyleOption(QStyleOptionButton option)
Initialize option with the values from this QCheckBox. This method is useful for subclasses when they need a QStyleOptionButton, but don't want to fill in all the information themselves.