28 mStyleOption.minimum = 0;
29 mStyleOption.maximum = 100;
32 setFocusPolicy( Qt::FocusPolicy( style()->styleHint( QStyle::SH_Button_FocusPolicy ) ) );
33 QSizePolicy sp( QSizePolicy::Expanding, QSizePolicy::Fixed, QSizePolicy::Slider );
34 if ( mStyleOption.orientation == Qt::Vertical )
37 setAttribute( Qt::WA_WState_OwnSizePolicy,
false );
39 setAttribute( Qt::WA_Hover );
40 setMouseTracking(
true );
45 return mStyleOption.maximum;
50 if ( mStyleOption.maximum ==
maximum )
54 mStyleOption.minimum = std::min(
maximum, mStyleOption.minimum );
59 mUpperValue = std::min( mUpperValue,
maximum );
60 mLowerValue = std::min( mLowerValue,
maximum );
69 return mStyleOption.minimum;
74 if ( mStyleOption.minimum ==
minimum )
77 mStyleOption.maximum = std::max(
minimum, mStyleOption.maximum );
82 mUpperValue = std::max( mUpperValue,
minimum );
83 mLowerValue = std::max( mLowerValue,
minimum );
95 if ( mStyleOption.minimum ==
minimum && mStyleOption.maximum ==
maximum )
102 if ( mUpperValue <
minimum || mLowerValue < minimum || mUpperValue >
maximum || mLowerValue >
maximum )
104 mUpperValue = std::min(
maximum, std::max( mUpperValue,
minimum ) );
105 mLowerValue = std::min(
maximum, std::max( mLowerValue,
minimum ) );
122 mLowerValue = std::min( mStyleOption.maximum, std::max( mStyleOption.minimum,
lowerValue ) );
123 if ( mFixedRangeSize >= 0 )
125 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
126 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
130 mUpperValue = std::max( mLowerValue, mUpperValue );
147 mUpperValue = std::max( mStyleOption.minimum, std::min( mStyleOption.maximum,
upperValue ) );
148 if ( mFixedRangeSize >= 0 )
150 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
151 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
155 mLowerValue = std::min( mLowerValue, mUpperValue );
164 if ( lower == mLowerValue && upper == mUpperValue )
168 std::swap( lower, upper );
170 mLowerValue = std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, lower ) );
171 mUpperValue = std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, upper ) );
172 if ( mFixedRangeSize >= 0 )
174 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
175 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
179 mUpperValue = std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, upper ) );
187 switch (
event->type() )
189 case QEvent::HoverEnter:
190 case QEvent::HoverLeave:
191 case QEvent::HoverMove:
192 if (
const QHoverEvent *he =
static_cast<const QHoverEvent *
>(
event ) )
193 updateHoverControl( he->pos() );
198 return QWidget::event(
event );
201int QgsRangeSlider::pick(
const QPoint &pt )
const
203 return mStyleOption.orientation == Qt::Horizontal ? pt.x() : pt.y();
206int QgsRangeSlider::pixelPosToRangeValue(
int pos )
const
208 const QRect gr = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderGroove,
this );
209 const QRect sr = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
210 int sliderMin, sliderMax, sliderLength;
211 if ( mStyleOption.orientation == Qt::Horizontal )
213 sliderLength = sr.width();
215 sliderMax = gr.right() - sliderLength + 1;
219 sliderLength = sr.height();
221 sliderMax = gr.bottom() - sliderLength + 1;
224 int value = QStyle::sliderValueFromPosition( mStyleOption.minimum, mStyleOption.maximum, pos - sliderMin,
225 sliderMax - sliderMin );
227 value = mStyleOption.maximum + mStyleOption.minimum - value;
231bool QgsRangeSlider::updateHoverControl(
const QPoint &pos )
233 const QRect lastHoverRect = mHoverRect;
234 const bool doesHover = testAttribute( Qt::WA_Hover );
235 if ( doesHover && newHoverControl( pos ) )
237 update( lastHoverRect );
238 update( mHoverRect );
244bool QgsRangeSlider::newHoverControl(
const QPoint &pos )
246 const Control lastHoverControl = mHoverControl;
247 const QStyle::SubControl lastHoverSubControl = mHoverSubControl;
249 mStyleOption.subControls = QStyle::SC_All;
251 mStyleOption.sliderPosition = unFlippedSliderPosition( mLowerValue );
252 const QRect lowerHandleRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
253 mStyleOption.sliderPosition = unFlippedSliderPosition( mUpperValue );
254 const QRect upperHandleRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
256 const QRect grooveRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderGroove,
this );
257 const QRect tickmarksRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderTickmarks,
this );
258 if ( lowerHandleRect.contains( pos ) )
260 mHoverRect = lowerHandleRect;
261 mHoverControl = Lower;
262 mHoverSubControl = QStyle::SC_SliderHandle;
263 setCursor( Qt::OpenHandCursor );
265 else if ( upperHandleRect.contains( pos ) )
267 mHoverRect = upperHandleRect;
268 mHoverControl = Upper;
269 mHoverSubControl = QStyle::SC_SliderHandle;
270 setCursor( Qt::OpenHandCursor );
272 else if ( grooveRect.contains( pos ) )
274 mHoverRect = grooveRect;
275 mHoverControl = None;
276 mHoverSubControl = QStyle::SC_SliderGroove;
278 if ( selectedRangeRect().contains( pos ) )
279 setCursor( Qt::OpenHandCursor );
283 else if ( tickmarksRect.contains( pos ) )
285 mHoverRect = tickmarksRect;
286 mHoverControl = None;
287 mHoverSubControl = QStyle::SC_SliderTickmarks;
292 mHoverRect = QRect();
293 mHoverControl = None;
294 mHoverSubControl = QStyle::SC_None;
297 return mHoverSubControl != lastHoverSubControl || mHoverControl != lastHoverControl;
300QRect QgsRangeSlider::selectedRangeRect()
304 mStyleOption.activeSubControls = mHoverControl == Lower || mActiveControl == Lower ? QStyle::SC_SliderHandle : QStyle::SC_None;
305 mStyleOption.sliderPosition = unFlippedSliderPosition( mLowerValue );
306 const QRect lowerHandleRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
nullptr );
308 mStyleOption.activeSubControls = mHoverControl == Upper || mActiveControl == Lower ? QStyle::SC_SliderHandle : QStyle::SC_None;
309 mStyleOption.sliderPosition = unFlippedSliderPosition( mUpperValue );
310 const QRect upperHandleRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
nullptr );
312 const QRect grooveRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderGroove,
nullptr );
314 switch ( mStyleOption.orientation )
317 selectionRect = mFlipped ? QRect( upperHandleRect.right(),
319 lowerHandleRect.left() - upperHandleRect.right(),
322 : QRect( lowerHandleRect.right(),
324 upperHandleRect.left() - lowerHandleRect.right(),
330 selectionRect = mFlipped ? QRect( grooveRect.x(),
331 lowerHandleRect.top(),
333 upperHandleRect.bottom() - lowerHandleRect.top()
335 : QRect( grooveRect.x(),
336 upperHandleRect.top(),
338 lowerHandleRect.bottom() - upperHandleRect.top()
343 return selectionRect.adjusted( -1, 1, 1, -1 );
348 return mFixedRangeSize;
353 if ( size == mFixedRangeSize )
356 mFixedRangeSize = size;
358 if ( mFixedRangeSize >= 0 )
364void QgsRangeSlider::applyStep(
int step )
366 switch ( mFocusControl )
370 const int newLowerValue = std::min( mUpperValue, std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, mLowerValue + step ) ) );
371 if ( newLowerValue != mLowerValue )
373 mLowerValue = newLowerValue;
374 if ( mFixedRangeSize >= 0 )
376 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
377 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
387 const int newUpperValue = std::max( mLowerValue, std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, mUpperValue + step ) ) );
388 if ( newUpperValue != mUpperValue )
390 mUpperValue = newUpperValue;
391 if ( mFixedRangeSize >= 0 )
393 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
394 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
406 const int previousWidth = mUpperValue - mLowerValue;
407 const int newLowerValue = std::min( mUpperValue, std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, mLowerValue + step ) ) );
408 if ( newLowerValue != mLowerValue )
410 mLowerValue = newLowerValue;
411 if ( mFixedRangeSize >= 0 )
413 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
414 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
418 mUpperValue = std::min( mStyleOption.maximum, mLowerValue + previousWidth );
426 const int previousWidth = mUpperValue - mLowerValue;
427 const int newUpperValue = std::max( mLowerValue, std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, mUpperValue + step ) ) );
428 if ( newUpperValue != mUpperValue )
430 mUpperValue = newUpperValue;
431 if ( mFixedRangeSize >= 0 )
433 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
434 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
438 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - previousWidth );
453int QgsRangeSlider::unFlippedSliderPosition(
int value )
const
455 return mFlipped ? mStyleOption.maximum + mStyleOption.minimum - value : value;
480 mStyleOption.tickPosition = position;
486 return mStyleOption.tickPosition;
491 mStyleOption.tickInterval = interval;
497 return mStyleOption.tickInterval;
503 if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) )
505 setSizePolicy( sizePolicy().transposed() );
506 setAttribute( Qt::WA_WState_OwnSizePolicy,
false );
514 return mStyleOption.orientation;
530 QPainter painter(
this );
532 mStyleOption.initFrom(
this );
533 mStyleOption.rect = rect();
534 mStyleOption.sliderPosition = mStyleOption.minimum;
535 mStyleOption.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderTickmarks;
537 mStyleOption.activeSubControls = mHoverSubControl;
539 style()->drawComplexControl( QStyle::CC_Slider, &mStyleOption, &painter );
541 QColor color = palette().color( QPalette::Highlight );
542 color.setAlpha( 160 );
543 painter.setBrush( QBrush( color ) );
544 painter.setPen( Qt::NoPen );
545 painter.drawRect( selectedRangeRect() );
548 mStyleOption.subControls = QStyle::SC_SliderHandle;
549 mStyleOption.activeSubControls = mHoverControl == Lower || mActiveControl == Lower ? QStyle::SC_SliderHandle : QStyle::SC_None;
550 mStyleOption.sliderPosition = unFlippedSliderPosition( mLowerValue );
551 if ( mActiveControl == Lower )
552 mStyleOption.state |= QStyle::State_Sunken;
554 mStyleOption.state &= ~QStyle::State_Sunken;
555 style()->drawComplexControl( QStyle::CC_Slider, &mStyleOption, &painter );
558 mStyleOption.activeSubControls = mHoverControl == Upper || mActiveControl == Lower ? QStyle::SC_SliderHandle : QStyle::SC_None;
559 mStyleOption.sliderPosition = unFlippedSliderPosition( mUpperValue );
560 if ( mActiveControl == Upper )
561 mStyleOption.state |= QStyle::State_Sunken;
563 mStyleOption.state &= ~QStyle::State_Sunken;
564 style()->drawComplexControl( QStyle::CC_Slider, &mStyleOption, &painter );
566 if ( hasFocus() && mFocusControl != None )
569 QStyleOptionFocusRect option;
570 option.initFrom(
this );
571 option.state = QStyle::State_KeyboardFocusChange;
572 if ( mFocusControl == Lower )
574 mStyleOption.sliderPosition = unFlippedSliderPosition( mLowerValue );
575 option.rect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
577 else if ( mFocusControl == Upper )
579 mStyleOption.sliderPosition = unFlippedSliderPosition( mUpperValue );
580 option.rect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
582 else if ( mFocusControl == Range )
584 option.rect = selectedRangeRect();
585 if ( mStyleOption.orientation == Qt::Horizontal )
586 option.rect = option.rect.adjusted( 0, -1, 0, 1 );
588 option.rect = option.rect.adjusted( -1, 0, 1, 0 );
590 style()->drawPrimitive( QStyle::PE_FrameFocusRect, &option, &painter );
596 if ( mStyleOption.maximum == mStyleOption.minimum || (
event->buttons() ^
event->button() ) )
604 mStyleOption.sliderPosition = unFlippedSliderPosition( mLowerValue );
605 const bool overLowerControl = style()->hitTestComplexControl( QStyle::CC_Slider, &mStyleOption,
event->pos(),
this ) == QStyle::SC_SliderHandle;
606 const QRect lowerSliderRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
607 mStyleOption.sliderPosition = unFlippedSliderPosition( mUpperValue );
608 const bool overUpperControl = style()->hitTestComplexControl( QStyle::CC_Slider, &mStyleOption,
event->pos(),
this ) == QStyle::SC_SliderHandle;
609 const QRect upperSliderRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
611 const bool overSelectedRange = selectedRangeRect().contains(
event->pos() );
613 mLowerClickOffset = pick(
event->pos() - lowerSliderRect.topLeft() );
614 mUpperClickOffset = pick(
event->pos() - upperSliderRect.topLeft() );
616 mPreDragLowerValue = mLowerValue;
617 mPreDragUpperValue = mUpperValue;
618 mRangeDragOffset = 0;
620 if ( ( overLowerControl || overUpperControl ) &&
event->modifiers() & Qt::ShiftModifier )
622 mActiveControl = Range;
623 mRangeDragOffset = overUpperControl ? mUpperClickOffset : mLowerClickOffset;
624 mFocusControl = overUpperControl ? Upper : Lower;
626 else if ( overLowerControl && overUpperControl )
627 mActiveControl = Both;
628 else if ( overLowerControl )
630 mActiveControl = Lower;
631 mFocusControl = Lower;
633 else if ( overUpperControl )
635 mActiveControl = Upper;
636 mFocusControl = Upper;
638 else if ( overSelectedRange )
640 mActiveControl = Range;
641 mFocusControl = Range;
644 mActiveControl = None;
646 if ( mActiveControl != None )
648 mStartDragPos = pixelPosToRangeValue( pick(
event->pos() ) - mRangeDragOffset );
654 if ( mActiveControl == None )
662 int newPosition = pixelPosToRangeValue( pick(
event->pos() ) );
664 bool changed =
false;
665 Control destControl = mActiveControl;
666 if ( destControl == Both )
669 if ( newPosition < mStartDragPos )
672 mFocusControl = Lower;
673 if ( mUpperValue != mPreDragUpperValue )
676 mUpperValue = mPreDragUpperValue;
677 if ( mFixedRangeSize >= 0 )
680 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
681 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
685 else if ( newPosition > mStartDragPos )
688 mFocusControl = Upper;
689 if ( mLowerValue != mPreDragLowerValue )
692 mLowerValue = mPreDragLowerValue;
693 if ( mFixedRangeSize >= 0 )
696 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
697 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
704 if ( mUpperValue != mPreDragUpperValue )
707 mUpperValue = mPreDragUpperValue;
708 if ( mFixedRangeSize >= 0 )
711 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
712 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
715 if ( mLowerValue != mPreDragLowerValue )
718 mLowerValue = mPreDragLowerValue;
719 if ( mFixedRangeSize >= 0 )
722 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
723 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
729 switch ( destControl )
738 newPosition = std::min( mUpperValue, pixelPosToRangeValue( pick(
event->pos() ) - mLowerClickOffset ) );
739 if ( mLowerValue != newPosition )
741 mLowerValue = newPosition;
742 if ( mFixedRangeSize >= 0 )
745 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
746 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
757 newPosition = std::max( mLowerValue, pixelPosToRangeValue( pick(
event->pos() ) - mUpperClickOffset ) );
758 if ( mUpperValue != newPosition )
760 mUpperValue = newPosition;
761 if ( mFixedRangeSize >= 0 )
764 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
765 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
775 newPosition = pixelPosToRangeValue( pick(
event->pos() ) - mRangeDragOffset ) ;
776 int delta = newPosition - mStartDragPos;
781 const int maxDelta = mStyleOption.maximum - mPreDragUpperValue;
782 delta = std::min( maxDelta, delta );
783 mLowerValue = mPreDragLowerValue + delta;
784 mUpperValue = mPreDragUpperValue + delta;
787 else if ( delta < 0 )
791 const int maxDelta = mPreDragLowerValue - mStyleOption.minimum ;
792 delta = std::min( maxDelta, delta );
793 mLowerValue = mPreDragLowerValue - delta;
794 mUpperValue = mPreDragUpperValue - delta;
811 if ( mActiveControl == None ||
event->buttons() )
818 mActiveControl = None;
824 Control destControl = mFocusControl;
825 if ( ( destControl == Lower || destControl == Upper ) && mLowerValue == mUpperValue )
828 switch (
event->key() )
832 switch ( mStyleOption.orientation )
835 if ( destControl == Both )
836 mFocusControl = mFlipped ? Upper : Lower;
838 applyStep( mFlipped ? mSingleStep : -mSingleStep );
844 switch ( mFocusControl )
847 mFocusControl = Range;
850 mFocusControl = Upper;
855 mFocusControl = Lower;
861 switch ( mFocusControl )
866 mFocusControl = Upper;
869 mFocusControl = Lower;
872 mFocusControl = Range;
884 switch ( mStyleOption.orientation )
887 if ( destControl == Both )
888 mFocusControl = mFlipped ? Lower : Upper;
889 applyStep( mFlipped ? -mSingleStep : mSingleStep );
895 switch ( mFocusControl )
900 mFocusControl = Upper;
903 mFocusControl = Lower;
906 mFocusControl = Range;
912 switch ( mFocusControl )
915 mFocusControl = Range;
918 mFocusControl = Upper;
923 mFocusControl = Lower;
935 switch ( mStyleOption.orientation )
940 switch ( mFocusControl )
943 mFocusControl = Range;
946 mFocusControl = Upper;
951 mFocusControl = Lower;
957 switch ( mFocusControl )
960 mFocusControl = Upper;
965 mFocusControl = Lower;
968 mFocusControl = Range;
976 if ( destControl == Both )
977 mFocusControl = mFlipped ? Upper : Lower;
979 applyStep( mFlipped ? mSingleStep : -mSingleStep );
987 switch ( mStyleOption.orientation )
992 switch ( mFocusControl )
995 mFocusControl = Upper;
1000 mFocusControl = Lower;
1003 mFocusControl = Range;
1009 switch ( mFocusControl )
1012 mFocusControl = Range;
1015 mFocusControl = Upper;
1020 mFocusControl = Lower;
1028 if ( destControl == Both )
1029 mFocusControl = mFlipped ? Lower : Upper;
1031 applyStep( mFlipped ? -mSingleStep : mSingleStep );
1037 case Qt::Key_PageUp:
1039 switch ( mStyleOption.orientation )
1041 case Qt::Horizontal:
1042 if ( destControl == Both )
1043 mFocusControl = mFlipped ? Lower : Upper;
1045 applyStep( mFlipped ? -mPageStep : mPageStep );
1049 if ( destControl == Both )
1050 mFocusControl = mFlipped ? Upper : Lower;
1052 applyStep( mFlipped ? mPageStep : -mPageStep );
1058 case Qt::Key_PageDown:
1060 switch ( mStyleOption.orientation )
1062 case Qt::Horizontal:
1063 if ( destControl == Both )
1064 mFocusControl = mFlipped ? Upper : Lower;
1066 applyStep( mFlipped ? mPageStep : -mPageStep );
1070 if ( destControl == Both )
1071 mFocusControl = mFlipped ? Lower : Upper;
1073 applyStep( mFlipped ? -mPageStep : mPageStep );
1080 switch ( destControl )
1083 applyStep( mFlipped ? mUpperValue - mLowerValue : mStyleOption.minimum - mLowerValue );
1087 applyStep( mFlipped ? mStyleOption.maximum - mUpperValue : mLowerValue - mUpperValue );
1091 applyStep( mFlipped ? mStyleOption.maximum - mUpperValue : mStyleOption.minimum - mLowerValue );
1095 if ( destControl == Both )
1096 mFocusControl = mFlipped ? Upper : Lower;
1098 applyStep( mFlipped ? mStyleOption.maximum - mUpperValue : mStyleOption.minimum - mLowerValue );
1108 switch ( destControl )
1111 applyStep( mFlipped ? mStyleOption.minimum - mLowerValue : mUpperValue - mLowerValue );
1115 applyStep( mFlipped ? mLowerValue - mUpperValue : mStyleOption.maximum - mUpperValue );
1119 applyStep( mFlipped ? mStyleOption.minimum - mLowerValue : mStyleOption.maximum - mUpperValue );
1123 if ( destControl == Both )
1124 mFocusControl = mFlipped ? Lower : Upper;
1126 applyStep( mFlipped ? mStyleOption.minimum - mLowerValue : mStyleOption.maximum - mUpperValue );
1145 static constexpr int SLIDER_LENGTH = 84;
1146 static constexpr int TICK_SPACE = 5;
1148 int thick = style()->pixelMetric( QStyle::PM_SliderThickness, &mStyleOption,
this );
1149 if ( mStyleOption.tickPosition & QSlider::TicksAbove )
1150 thick += TICK_SPACE;
1151 if ( mStyleOption.tickPosition & QSlider::TicksBelow )
1152 thick += TICK_SPACE;
1153 int w = thick, h = SLIDER_LENGTH;
1154 if ( mStyleOption.orientation == Qt::Horizontal )
1158 return style()->sizeFromContents( QStyle::CT_Slider, &mStyleOption, QSize( w, h ),
this );
1164 const int length = style()->pixelMetric( QStyle::PM_SliderLength, &mStyleOption,
this );
1165 if ( mStyleOption.orientation == Qt::Horizontal )
1166 s.setWidth( length );
1168 s.setHeight( length );
A slider control with two interactive endpoints, for interactive selection of a range of values.
void setUpperValue(int value)
Sets the upper value for the range currently selected in the widget.
void setRangeLimits(int minimum, int maximum)
Sets the minimum and maximum range limits for values allowed in the widget.
QgsRangeSlider(QWidget *parent=nullptr)
Constructor for QgsRangeSlider, with the specified parent widget.
void setOrientation(Qt::Orientation orientation)
Sets the orientation of the slider.
void setTickInterval(int interval)
Sets the interval for tick marks shown in the widget.
int upperValue() const
Returns the upper value for the range selected in the widget.
int tickInterval() const
Returns the interval for tick marks shown in the widget.
void paintEvent(QPaintEvent *event) override
void fixedRangeSizeChanged(int size)
Emitted when the widget's fixed range size is changed.
void rangeLimitsChanged(int minimum, int maximum)
Emitted when the limits of values allowed in the widget is changed.
QSize sizeHint() const override
void keyPressEvent(QKeyEvent *event) override
void mouseMoveEvent(QMouseEvent *event) override
void rangeChanged(int minimum, int maximum)
Emitted when the range selected in the widget is changed.
int maximum() const
Returns the maximum value allowed by the widget.
void mousePressEvent(QMouseEvent *event) override
bool event(QEvent *event) override
void setSingleStep(int step)
Sets the single step value for the widget.
void setMinimum(int minimum)
Sets the minimum value allowed in the widget.
void setPageStep(int step)
Sets the page step value for the widget.
Qt::Orientation orientation() const
Returns the orientation of the slider.
void setMaximum(int maximum)
Sets the maximum value allowed in the widget.
int pageStep() const
Returns the page step value for the widget.
void setFlippedDirection(bool flipped)
Sets whether the slider has its values flipped.
int fixedRangeSize() const
Returns the slider's fixed range size, or -1 if not set.
int minimum() const
Returns the minimum value allowed by the widget.
QSize minimumSizeHint() const override
void setRange(int lower, int upper)
Sets the current range selected in the widget.
void setLowerValue(int value)
Sets the lower value for the range currently selected in the widget.
int lowerValue() const
Returns the lower value for the range selected in the widget.
void setTickPosition(QSlider::TickPosition position)
Sets the position of the tick marks shown in the widget.
void setFixedRangeSize(int size)
Sets the slider's fixed range size.
void mouseReleaseEvent(QMouseEvent *event) override
bool flippedDirection() const
Returns true if the slider has its values flipped.
QSlider::TickPosition tickPosition() const
Returns the position of the tick marks shown in the widget.
int singleStep() const
Returns the single step value for the widget.