QSlider Class Reference

The QSlider widget provides a vertical or horizontal slider.

  1. #include <QSlider>

Inherits: QAbstractSlider.

Inherited by:

Detailed Description

The QSlider 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 in QAbstractSlider. The most useful functions are setValue() 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; and setMinimum() and setMaximum() to define the range of the scroll bar.

QSlider provides methods for controlling tickmarks. You can use setTickPosition() 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 the tickPosition() and tickInterval() functions, respectively.

QSlider inherits a comprehensive set of signals:

SignalDescription
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 although QSlider 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:

  • Left/Right move a horizontal slider by one single step.
  • Up/Down move a vertical slider by one single step.
  • PageUp moves up one page.
  • PageDown moves down one page.
  • Home moves to the start (mininum).
  • End moves to the end (maximum).
Screenshot of a Macintosh slider

Screenshot of a Macintosh slider

A slider shown in the Macintosh widget style.
Screenshot of a Windows XP slider

Screenshot of a Windows XP slider

A slider shown in the Windows XP widget style.
Screenshot of a Plastique slider

Screenshot of a Plastique slider

A slider shown in the Plastique widget style.

See also QScrollBar, QSpinBox, QDial, GUI Design Handbook: Slider, and Sliders Example.

Public Types

Toggle detailsenum QSlider::

TickPositionTickPosition { NoTicks , TicksAbove , TicksLeft , TicksBelow , TicksRight , TicksBothSides , NoMarks , Above , Left , Below , Right , Both TicksBothSides ...} { NoTicks , TicksAbove , TicksLeft , TicksBelow , TicksRight , TicksBothSides , NoMarks , Above , Left , Below , Right , Both TicksBothSides }

This enum specifies where the tick marks are to be drawn relative to the slider's groove and the handle the user moves.

ConstantValueDescription
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

Look up this member in the source code.

    Properties

    Toggle detailstickIntervaltickInterval : int

    This property holds the interval between tickmarks

    This is a value interval, not a pixel interval. If it is 0, the slider will choose between singleStep() and pageStep().

    The default value is 0.

    See also tickPosition, lineStep(), and pageStep().

    Access functions:

    Look up this member in the source code.

    Toggle detailstickPositiontickPosition : TickPosition

    This property holds the tickmark position for this slider

    The valid values are described by the QSlider::TickPosition enum.

    The default value is QSlider::NoTicks.

    See also tickInterval.

    Access functions:

    Look up this member in the source code.

      Public Functions

      Toggle details QSlider

      QSliderQSlider ( QWidget *parent=0 ) ( QWidget *parent=0 )

      Constructs a vertical slider with the given parent.

      Look up this member in the source code.

      Toggle details QSlider

      QSliderQSlider ( Qt::Orientation orientation , QWidget *parent=0 ...) ( Qt::Orientation orientation , QWidget *parent=0 )

      Constructs a slider with the given parent. The orientation parameter determines whether the slider is horizontal or vertical; the valid values are Qt::Vertical and Qt::Horizontal.

      Look up this member in the source code.

      Toggle details QSlider

      ~QSlider~QSlider () ()

      Destroys this slider.

      Look up this member in the source code.

      Toggle details bool QSlider

      eventevent ( QEvent *event ) ( QEvent *event ) [virtual]

      Reimplemented from QObject::event().

      Look up this member in the source code.

      Toggle details void QSlider

      initStyleOptioninitStyleOption ( QStyleOptionSlider *option ) ( QStyleOptionSlider *option )const[protected]

      Initialize option with the values from this QSlider. This method is useful for subclasses when they need a QStyleOptionSlider, but don't want to fill in all the information themselves.

      See also QStyleOption::initFrom().

      Look up this member in the source code.

      Toggle details QSize QSlider

      minimumSizeHintminimumSizeHint () ()const [virtual]

      Reimplemented from QWidget::minimumSizeHint().

      Look up this member in the source code.

      Toggle details void QSlider

      mouseMoveEventmouseMoveEvent ( QMouseEvent *ev ) ( QMouseEvent *ev ) [virtual protected]

      Reimplemented from QWidget::mouseMoveEvent().

      Look up this member in the source code.

      Toggle details void QSlider

      mousePressEventmousePressEvent ( QMouseEvent *ev ) ( QMouseEvent *ev ) [virtual protected]

      Reimplemented from QWidget::mousePressEvent().

      Look up this member in the source code.

      Toggle details void QSlider

      mouseReleaseEventmouseReleaseEvent ( QMouseEvent *ev ) ( QMouseEvent *ev ) [virtual protected]

      Reimplemented from QWidget::mouseReleaseEvent().

      Look up this member in the source code.

      Toggle details void QSlider

      paintEventpaintEvent ( QPaintEvent *ev ) ( QPaintEvent *ev ) [virtual protected]

      Reimplemented from QWidget::paintEvent().

      Look up this member in the source code.

      Toggle details QSize QSlider

      sizeHintsizeHint () ()const [virtual]

      Reimplemented from QWidget::sizeHint().

      Look up this member in the source code.

      Toggle details QSlider

      QSliderQSlider ( QWidget *parent , const char *name ) ( QWidget *parent , const char *name ) Qt3-support

      Use QSlider() and QObject::setObjectName() instead.

      For example, if you have code like

      1. QSlider *mySlider = new QSlider(parent, name);

      you can rewrite it as

      1.                     QSlider *mySlider = new QSlider(parent);
      2. mySlider->setObjectName(name);

      Look up this member in the source code.

      Toggle details QSlider

      QSliderQSlider ( Qt::Orientation orientation , QWidget *parent , const char *name ...) ( Qt::Orientation orientation , QWidget *parent , const char *name ) Qt3-support

      Use QSlider() and QObject::setObjectName() instead.

      For example, if you have code like

      1. QSlider *mySlider = new QSlider(orientation, parent, name);

      you can rewrite it as

      1.                     QSlider *mySlider = new QSlider(orientation, parent);
      2. mySlider->setObjectName(name);

      Look up this member in the source code.

      Toggle details QSlider

      QSliderQSlider ( int minValue , int maxValue , int pageStep , int value , Qt::Orientation orientation , QWidget *parent=0 , const char *name=0 ...) ( int minValue , int maxValue , int pageStep , int value , Qt::Orientation orientation , QWidget *parent=0 , const char *name=0 ) Qt3-support

      Use QSlider(), QObject::setObjectName() and the functionality inherited from QAbstractSlider instead.

      For example, if you have code like

      1. QSlider *mySlider = new QSlider(minValue, maxValue, pageStep,
      2.                                 value, orientation, parent, name);

      you can rewrite it as

      1.                     QSlider *mySlider = new QSlider(orientation, parent);
      2. mySlider->setObjectName(name);
      3. mySlider->setMinimum(minValue);
      4. mySlider->setMaximum(maxValue);
      5. mySlider->setPageStep(pageStep);
      6. mySlider->setValue(value);

      Look up this member in the source code.

      Toggle details void QSlider

      setTickmarkssetTickmarks ( TickPosition position ) ( TickPosition position ) Qt3-support

      Use setTickPosition() instead.

      See also tickmarks().

      Look up this member in the source code.

      Toggle details TickPosition QSlider

      tickmarkstickmarks () ()const Qt3-support

      Use tickPosition() instead.

      See also setTickmarks().

      Look up this member in the source code.

      Public Slots

      Toggle details void QSlider

      addStepaddStep () () [slot] Qt3-support

      Use setValue() instead.

      Look up this member in the source code.

      Toggle details void QSlider

      subtractStepsubtractStep () () [slot] Qt3-support

      Use setValue() instead.

      Look up this member in the source code.

      Notes provided by the Qt Community

      No notes