📄 qabstractslider.cpp
字号:
else emit sliderReleased(); } if (!down && d->position != d->value) triggerAction(SliderMove);}bool QAbstractSlider::isSliderDown() const{ Q_D(const QAbstractSlider); return d->pressed;}/*! \property QAbstractSlider::sliderPosition \brief the current slider position If \l tracking is enabled (the default), this is identical to \l value.*/void QAbstractSlider::setSliderPosition(int position){ Q_D(QAbstractSlider); position = d->bound(position); if (position == d->position) return; d->position = position; if (!d->tracking) update(); if (d->pressed) emit sliderMoved(position); if (d->tracking && !d->blocktracking) triggerAction(SliderMove);}int QAbstractSlider::sliderPosition() const{ Q_D(const QAbstractSlider); return d->position;}/*! \property QAbstractSlider::value \brief the slider's current value The slider forces the value to be within the legal range: \l minimum <= \c value <= \l maximum. Changing the value also changes the \l sliderPosition.*/int QAbstractSlider::value() const{ Q_D(const QAbstractSlider); return d->value;}void QAbstractSlider::setValue(int value){ Q_D(QAbstractSlider); value = d->bound(value); if (d->value == value && d->position == value) return; d->value = value; if (d->position != value) { d->position = value; if (d->pressed) emit sliderMoved((d->position = value)); }#ifndef QT_NO_ACCESSIBILITY QAccessible::updateAccessibility(this, 0, QAccessible::ValueChanged);#endif sliderChange(SliderValueChange); emit valueChanged(value);}/*! \property QAbstractSlider::invertedAppearance \brief whether or not a slider shows its values inverted. If this property is false (the default), the minimum and maximum will be shown in its classic position for the inherited widget. If the value is true, the minimum and maximum appear at their opposite location. Note: This property makes most sense for sliders and dials. For scroll bars, the visual effect of the scroll bar subcontrols depends on whether or not the styles understand inverted appearance; most styles ignore this property for scroll bars.*/bool QAbstractSlider::invertedAppearance() const{ Q_D(const QAbstractSlider); return d->invertedAppearance;}void QAbstractSlider::setInvertedAppearance(bool invert){ Q_D(QAbstractSlider); d->invertedAppearance = invert; update();}/*! \property QAbstractSlider::invertedControls \brief whether or not the slider inverts its wheel and key events. If this property is false, scrolling the mouse wheel "up" and using keys like page up will increase the slider's value towards its maximum. Otherwise pressing page up will move value towards the slider's minimum.*/bool QAbstractSlider::invertedControls() const{ Q_D(const QAbstractSlider); return d->invertedControls;}void QAbstractSlider::setInvertedControls(bool invert){ Q_D(QAbstractSlider); d->invertedControls = invert;}/*! Triggers a slider \a action. Possible actions are \l SliderSingleStepAdd, \l SliderSingleStepSub, \l SliderPageStepAdd, \l SliderPageStepSub, \l SliderToMinimum, \l SliderToMaximum, and \l SliderMove. \sa actionTriggered() */void QAbstractSlider::triggerAction(SliderAction action){ Q_D(QAbstractSlider); d->blocktracking = true; switch (action) { case SliderSingleStepAdd: setSliderPosition(d->value + d->singleStep); break; case SliderSingleStepSub: setSliderPosition(d->value - d->singleStep); break; case SliderPageStepAdd: setSliderPosition(d->value + d->pageStep); break; case SliderPageStepSub: setSliderPosition(d->value - d->pageStep); break; case SliderToMinimum: setSliderPosition(d->minimum); break; case SliderToMaximum: setSliderPosition(d->maximum); break; case SliderMove: case SliderNoAction: break; }; emit actionTriggered(action); d->blocktracking = false; setValue(d->position);}/*! Sets action \a action to be triggered repetitively in intervalsof \a repeatTime, after an initial delay of \a thresholdTime.\sa triggerAction() repeatAction() */void QAbstractSlider::setRepeatAction(SliderAction action, int thresholdTime, int repeatTime){ Q_D(QAbstractSlider); if ((d->repeatAction = action) == SliderNoAction) { d->repeatActionTimer.stop(); } else { d->repeatActionTime = repeatTime; d->repeatActionTimer.start(thresholdTime, this); }}/*! Returns the current repeat action. \sa setRepeatAction() */QAbstractSlider::SliderAction QAbstractSlider::repeatAction() const{ Q_D(const QAbstractSlider); return d->repeatAction;}/*!\reimp */void QAbstractSlider::timerEvent(QTimerEvent *e){ Q_D(QAbstractSlider); if (e->timerId() == d->repeatActionTimer.timerId()) { if (d->repeatActionTime) { // was threshold time, use repeat time next time d->repeatActionTimer.start(d->repeatActionTime, this); d->repeatActionTime = 0; } if (d->repeatAction == SliderPageStepAdd) d->setAdjustedSliderPosition(d->value + d->pageStep); else if (d->repeatAction == SliderPageStepSub) d->setAdjustedSliderPosition(d->value - d->pageStep); else triggerAction(d->repeatAction); }}/*! Reimplement this virtual function to track slider changes such as \l SliderRangeChange, \l SliderOrientationChange, \l SliderStepsChange, or \l SliderValueChange. The default implementation only updates the display and ignores the \a change parameter. */void QAbstractSlider::sliderChange(SliderChange){ update();}/*! \reimp*/#ifndef QT_NO_WHEELEVENTvoid QAbstractSlider::wheelEvent(QWheelEvent * e){ Q_D(QAbstractSlider); e->ignore(); if (e->orientation() != d->orientation && !rect().contains(e->pos())) return; static qreal offset = 0; static QAbstractSlider *offset_owner = 0; if (offset_owner != this){ offset_owner = this; offset = 0; } int step = qMin(QApplication::wheelScrollLines() * d->singleStep, d->pageStep); if ((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::ShiftModifier)) step = d->pageStep; offset += e->delta() * step / 120; if (d->invertedControls) offset = -offset; if (qAbs(offset) < 1) return; int prevValue = d->value; d->position = d->value + int(offset); // value will be updated by triggerAction() triggerAction(SliderMove); if (prevValue == d->value) { offset = 0; } else { offset -= int(offset); e->accept(); }}#endif/*! \reimp*/void QAbstractSlider::keyPressEvent(QKeyEvent *ev){ Q_D(QAbstractSlider); SliderAction action = SliderNoAction; switch (ev->key()) {#ifdef QT_KEYPAD_NAVIGATION case Qt::Key_Select: if (QApplication::keypadNavigationEnabled()) setEditFocus(!hasEditFocus()); else ev->ignore(); break; case Qt::Key_Back: if (QApplication::keypadNavigationEnabled() && hasEditFocus()) { setValue(d->origValue); setEditFocus(false); } else ev->ignore(); break;#endif // It seems we need to use invertedAppearance for Left and right, otherwise, things look weird. case Qt::Key_Left:#ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { ev->ignore(); return; } if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical) action = d->invertedControls ? SliderSingleStepSub : SliderSingleStepAdd; else#endif action = !d->invertedAppearance ? SliderSingleStepSub : SliderSingleStepAdd; break; case Qt::Key_Right:#ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { ev->ignore(); return; } if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical) action = d->invertedControls ? SliderSingleStepAdd : SliderSingleStepSub; else#endif action = !d->invertedAppearance ? SliderSingleStepAdd : SliderSingleStepSub; break; case Qt::Key_Up:#ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled()) { ev->ignore(); break; }#endif action = d->invertedControls ? SliderSingleStepSub : SliderSingleStepAdd; break; case Qt::Key_Down:#ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled()) { ev->ignore(); break; }#endif action = d->invertedControls ? SliderSingleStepAdd : SliderSingleStepSub; break; case Qt::Key_PageUp: action = d->invertedControls ? SliderPageStepSub : SliderPageStepAdd; break; case Qt::Key_PageDown: action = d->invertedControls ? SliderPageStepAdd : SliderPageStepSub; break; case Qt::Key_Home: action = SliderToMinimum; break; case Qt::Key_End: action = SliderToMaximum; break; default: ev->ignore(); break; } if (action) triggerAction(action);}/*! \reimp*/void QAbstractSlider::changeEvent(QEvent *ev){ Q_D(QAbstractSlider); switch (ev->type()) { case QEvent::EnabledChange: if (!isEnabled()) { d->repeatActionTimer.stop(); setSliderDown(false); } // fall through... default: QWidget::changeEvent(ev); }}/*! \reimp*/bool QAbstractSlider::event(QEvent *e){#ifdef QT_KEYPAD_NAVIGATION Q_D(QAbstractSlider); switch (e->type()) { case QEvent::FocusIn: d->origValue = d->value; break; default: break; }#endif return QWidget::event(e);}/*! \fn int QAbstractSlider::minValue() const Use minimum() instead.*//*! \fn int QAbstractSlider::maxValue() const Use maximum() instead.*//*! \fn int QAbstractSlider::lineStep() const Use singleStep() instead.*//*! \fn void QAbstractSlider::setMinValue(int v) Use setMinimum() instead.*//*! \fn void QAbstractSlider::setMaxValue(int v) Use setMaximum() instead.*//*! \fn void QAbstractSlider::setLineStep(int v) Use setSingleStep() instead.*//*! \fn void QAbstractSlider::addPage() Use triggerAction(QAbstractSlider::SliderPageStepAdd) instead.*//*! \fn void QAbstractSlider::subtractPage() Use triggerAction(QAbstractSlider::SliderPageStepSub) instead.*//*! \fn void QAbstractSlider::addLine() Use triggerAction(QAbstractSlider::SliderSingleStepAdd) instead.*//*! \fn void QAbstractSlider::subtractLine() Use triggerAction(QAbstractSlider::SliderSingleStepSub) instead.*//*! \fn void QAbstractSlider::setSteps(int single, int page) Use setSingleStep(\a single) followed by setPageStep(\a page) instead.*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -