16#include <QtCore/qelapsedtimer.h>
17#include <QtCore/qpointer.h>
20#if QT_CONFIG(accessibility)
168 q->update(lastHoverRect);
178 QStyleOptionSlider
opt;
179 q->initStyleOption(&
opt);
194 if (
q->isVisible()) {
195 QStyleOptionSlider
opt;
196 q->initStyleOption(&
opt);
208 QStyleOptionSlider
opt;
209 q->initStyleOption(&
opt);
248 q_func()->setRepeatAction(action, threshold);
249 q_func()->triggerAction(action);
261 q->setSliderDown(
false);
263 QStyleOptionSlider
opt;
264 q->initStyleOption(&
opt);
284 option->orientation =
d->orientation;
287 option->sliderPosition =
d->position;
288 option->sliderValue =
d->value;
289 option->singleStep =
d->singleStep;
290 option->pageStep =
d->pageStep;
291 option->upsideDown =
d->invertedAppearance;
299#define HORIZONTAL (d_func()->orientation == Qt::Horizontal)
300#define VERTICAL !HORIZONTAL
360 q->setSizePolicy(
sp);
365#ifndef QT_NO_CONTEXTMENU
389 if (actionSelected ==
nullptr)
391 else if (actionSelected == actScrollHere)
392 setValue(d_func()->pixelPosToRangeValue(horiz ?
event->pos().x() :
event->pos().y()));
393 else if (actionSelected == actScrollTop)
395 else if (actionSelected == actScrollBottom)
397 else if (actionSelected == actPageUp)
399 else if (actionSelected == actPageDn)
401 else if (actionSelected == actScrollUp)
403 else if (actionSelected == actScrollDn)
414 QStyleOptionSlider
opt;
421 size =
QSize(scrollBarExtent * 2 + scrollBarSliderMin, scrollBarExtent);
423 size =
QSize(scrollBarExtent, scrollBarExtent * 2 + scrollBarSliderMin);
440 switch(
event->type()) {
445 d_func()->updateHoverControl(he->position().toPoint());
448 QStyleOptionSlider
opt;
455 QStyleOptionSlider
opt;
474#if QT_CONFIG(wheelevent)
475void QScrollBar::wheelEvent(QWheelEvent *
event)
489 int delta = horizontal ? -
event->angleDelta().x() :
event->angleDelta().y();
495 d->setTransient(
false);
497 d->setTransient(
true);
508 QStyleOptionSlider
opt;
511 if (
d->pressedControl) {
513 if (!
d->pointerOutsidePressedControl)
528 if (
d->repeatActionTimer.isActive())
529 d->stopRepeatAction();
533 QStyleOptionSlider
opt;
537 if (
d->maximum ==
d->minimum
543 d->pointerOutsidePressedControl =
false;
548 QPoint pressValue = click - sr.center() + sr.topLeft();
549 d->pressValue =
d->orientation ==
Qt::Horizontal ?
d->pixelPosToRangeValue(pressValue.
x()) :
550 d->pixelPosToRangeValue(pressValue.
y());
552 d->clickOffset =
HORIZONTAL ? (click.
x()-sr.x()) : (click.
y()-sr.y());
553 d->snapBackPosition =
d->position;
561 int sliderLength =
HORIZONTAL ? sr.width() : sr.height();
565 d->clickOffset = sliderLength / 2;
567 const int initialDelay = 500;
570 d->activateControl(
d->pressedControl, initialDelay);
572 if (
time.elapsed() >= initialDelay &&
d->repeatActionTimer.isActive()) {
579 d->repeatActionTimer.start(50,
this);
592 if (!
d->pressedControl)
598 d->stopRepeatAction();
608 if (!
d->pressedControl)
611 QStyleOptionSlider
opt;
620 int newPosition =
d->pixelPosToRangeValue((
HORIZONTAL ? click.
x() : click.
y()) -
d->clickOffset);
624 r.adjust(-
m, -
m,
m,
m);
626 newPosition =
d->snapBackPosition;
634 if (newSc ==
d->pressedControl && !
d->pointerOutsidePressedControl)
637 d->pointerOutsidePressedControl =
false;
640 d->pressedControl = newSc;
641 d->activateControl(
d->pressedControl, 0);
650 if (pr.contains(e->
position().
toPoint()) ==
d->pointerOutsidePressedControl) {
651 if ((
d->pointerOutsidePressedControl = !
d->pointerOutsidePressedControl)) {
652 d->pointerOutsidePressedControl =
true;
656 d->activateControl(
d->pressedControl);
666 QStyleOptionSlider
opt;
667 q->initStyleOption(&
opt);
672 int sliderMin, sliderMax, sliderLength;
675 sliderLength = sr.
width();
677 sliderMax = gr.right() - sliderLength + 1;
679 opt.upsideDown = !
opt.upsideDown;
681 sliderLength = sr.height();
683 sliderMax = gr.bottom() - sliderLength + 1;
687 sliderMax - sliderMin,
opt.upsideDown);
695 if (
d->pressedControl) {
706 QStyleOptionSlider
opt;
707 scrollbar->initStyleOption(&
opt);
713#include "moc_qscrollbar.cpp"
Qt::Orientation orientation
The QAbstractSlider class provides an integer value within a range.
void setRepeatAction(SliderAction action, int thresholdTime=500, int repeatTime=50)
Sets action action to be triggered repetitively in intervals of repeatTime, after an initial delay of...
virtual void sliderChange(SliderChange change)
Reimplement this virtual function to track slider changes such as \l SliderRangeChange,...
SliderAction
\value SliderNoAction \value SliderSingleStepAdd \value SliderSingleStepSub \value SliderPageStepAdd ...
Qt::Orientation orientation
the orientation of the slider
bool event(QEvent *e) override
\reimp
void setSliderPosition(int)
SliderChange
\value SliderRangeChange \value SliderOrientationChange \value SliderStepsChange \value SliderValueCh...
void triggerAction(SliderAction action)
Triggers a slider action.
The QAction class provides an abstraction for user commands that can be added to different user inter...
The QHideEvent class provides an event which is sent after a widget is hidden.
void killTimer(int id)
Kills the timer with timer identifier, id.
The QPaintEvent class contains event parameters for paint events.
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
\inmodule QtCore\reentrant
constexpr int x() const noexcept
Returns the x coordinate of this point.
constexpr int y() const noexcept
Returns the y coordinate of this point.
\inmodule QtCore\reentrant
constexpr int width() const noexcept
Returns the width of the rectangle.
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
Qt::MouseButton button() const
Returns the button that caused the event.
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
The QStyleOption class stores the parameters used by QStyle functions.
void initFrom(const QWidget *w)
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget.
virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget=nullptr) const =0
Returns the rectangle containing the specified subControl of the given complex control (with the styl...
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=nullptr) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
@ SH_ScrollBar_RollBetweenButtons
@ SH_ScrollBar_MiddleClickAbsolutePosition
@ SH_ScrollBar_LeftClickAbsolutePosition
@ SH_ScrollBar_ContextMenu
@ SH_ScrollBar_ScrollWhenPointerLeavesControl
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
virtual SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *widget=nullptr) const =0
Returns the sub control at the given position in the given complex control (with the style options sp...
static int sliderValueFromPosition(int min, int max, int pos, int space, bool upsideDown=false)
Converts the given pixel position to a logical value.
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
Returns the value of the given pixel metric.
SubControl
This enum describes the available sub controls.
EGLImageKHR int int EGLuint64KHR * modifiers
Combined button and popup list for selecting options.
@ WA_WState_OwnSizePolicy
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
constexpr T qAbs(const T &t)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble GLdouble GLdouble q