
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQSlider widget provides a vertical or horizontal slider.More...
| Header: | #include <QSlider> |
| Inherits: | QAbstractSlider |
| enum | TickPosition { NoTicks, TicksBothSides, TicksAbove, TicksBelow, TicksLeft, TicksRight } |
| QSlider(QWidget * parent = 0) | |
| QSlider(Qt::Orientation orientation, QWidget * parent = 0) | |
| ~QSlider() | |
| void | setTickInterval(int ti) |
| void | setTickPosition(TickPosition position) |
| int | tickInterval() const |
| TickPosition | tickPosition() const |
| virtual bool | event(QEvent * event) |
| virtual QSize | minimumSizeHint() const |
| virtual QSize | sizeHint() const |
| void | initStyleOption(QStyleOptionSlider * option) const |
| virtual void | mouseMoveEvent(QMouseEvent * ev) |
| virtual void | mousePressEvent(QMouseEvent * ev) |
| virtual void | mouseReleaseEvent(QMouseEvent * ev) |
| virtual void | paintEvent(QPaintEvent * ev) |
TheQSlider widget provides a vertical or horizontal slider.
The slider is the classic widget for controlling a bounded value. It lets the user move a slider handle along a horizontal or vertical groove and translates the handle's position into an integer value within the legal range.
QSlider has very few of its own functions; most of the functionality is inQAbstractSlider. The most useful functions aresetValue() to set the slider directly to some value;triggerAction() to simulate the effects of clicking (useful for shortcut keys);setSingleStep(),setPageStep() to set the steps; andsetMinimum() andsetMaximum() to define the range of the scroll bar.
QSlider provides methods for controlling tickmarks. You can usesetTickPosition() to indicate where you want the tickmarks to be,setTickInterval() to indicate how many of them you want. the currently set tick position and interval can be queried using thetickPosition() andtickInterval() functions, respectively.
QSlider inherits a comprehensive set of signals:
| Signal | Description |
|---|---|
| valueChanged() | Emitted when the slider's value has changed. The tracking() determines whether this signal is emitted during user interaction. |
| sliderPressed() | Emitted when the user starts to drag the slider. |
| sliderMoved() | Emitted when the user drags the slider. |
| sliderReleased() | Emitted when the user releases the slider. |
QSlider only provides integer ranges. Note that althoughQSlider handles very large numbers, it becomes difficult for users to use a slider accurately for very large ranges.
A slider accepts focus on Tab and provides both a mouse wheel and a keyboard interface. The keyboard interface is the following:
![]() | A slider shown in theMacintosh widget style. |
![]() | A slider shown in theWindows XP widget style. |
![]() | A slider shown in thePlastique widget style. |
See alsoQScrollBar,QSpinBox,QDial,GUI Design Handbook: Slider, andSliders Example.
This enum specifies where the tick marks are to be drawn relative to the slider's groove and the handle the user moves.
| Constant | Value | Description |
|---|---|---|
QSlider::NoTicks | 0 | Do not draw any tick marks. |
QSlider::TicksBothSides | 3 | Draw tick marks on both sides of the groove. |
QSlider::TicksAbove | 1 | Draw tick marks above the (horizontal) slider |
QSlider::TicksBelow | 2 | Draw tick marks below the (horizontal) slider |
QSlider::TicksLeft | TicksAbove | Draw tick marks to the left of the (vertical) slider |
QSlider::TicksRight | TicksBelow | Draw tick marks to the right of the (vertical) slider |
This property holds the interval between tickmarks.
This is a value interval, not a pixel interval. If it is 0, the slider will choose betweensingleStep() andpageStep().
The default value is 0.
Access functions:
| int | tickInterval() const |
| void | setTickInterval(int ti) |
See alsotickPosition,lineStep(), andpageStep().
This property holds the tickmark position for this slider.
The valid values are described by theQSlider::TickPosition enum.
The default value isQSlider::NoTicks.
Access functions:
| TickPosition | tickPosition() const |
| void | setTickPosition(TickPosition position) |
See alsotickInterval.
Constructs a vertical slider with the givenparent.
Constructs a slider with the givenparent. Theorientation parameter determines whether the slider is horizontal or vertical; the valid values areQt::Vertical andQt::Horizontal.
Destroys this slider.
[virtual]bool QSlider::event(QEvent * event)Reimplemented fromQObject::event().
[protected]void QSlider::initStyleOption(QStyleOptionSlider * option) constInitializeoption with the values from thisQSlider. This method is useful for subclasses when they need aQStyleOptionSlider, but don't want to fill in all the information themselves.
See alsoQStyleOption::initFrom().
[virtual]QSize QSlider::minimumSizeHint() constReimplemented fromQWidget::minimumSizeHint().
[virtual protected]void QSlider::mouseMoveEvent(QMouseEvent * ev)Reimplemented fromQWidget::mouseMoveEvent().
[virtual protected]void QSlider::mousePressEvent(QMouseEvent * ev)Reimplemented fromQWidget::mousePressEvent().
[virtual protected]void QSlider::mouseReleaseEvent(QMouseEvent * ev)Reimplemented fromQWidget::mouseReleaseEvent().
[virtual protected]void QSlider::paintEvent(QPaintEvent * ev)Reimplemented fromQWidget::paintEvent().
[virtual]QSize QSlider::sizeHint() constReimplemented fromQWidget::sizeHint().
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.