Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickscrollbar.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qquickscrollbar_p.h"
7
8#include <QtQml/qqmlinfo.h>
9#include <QtQuick/private/qquickflickable_p.h>
10#if QT_CONFIG(accessibility)
11#include <QtQuick/private/qquickaccessibleattached_p.h>
12#endif
13
15
20
125static const QQuickItemPrivate::ChangeTypes QsbChangeTypes = QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed;
126static const QQuickItemPrivate::ChangeTypes QsbHorizontalChangeTypes = QsbChangeTypes | QQuickItemPrivate::ImplicitHeight;
127static const QQuickItemPrivate::ChangeTypes QsbVerticalChangeTypes = QsbChangeTypes | QQuickItemPrivate::ImplicitWidth;
128
130{
131 qreal visualPos = position;
132
133 if (minimumSize > size && size != 1.0)
134 visualPos = position / (1.0 - size) * (1.0 - minimumSize);
135
136 qreal maximumSize = qMax<qreal>(0.0, 1.0 - visualPos);
137 qreal visualSize = qMax<qreal>(minimumSize,
138 qMin<qreal>(qMax(size, minimumSize) + qMin<qreal>(0, visualPos),
139 maximumSize));
140
141 visualPos = qMax<qreal>(0,qMin<qreal>(visualPos,qMax<qreal>(0, 1.0 - visualSize)));
142
143 return VisualArea(visualPos, visualSize);
144}
145
147{
148 if (minimumSize > size && minimumSize != 1.0)
149 return position * (1.0 - size) / (1.0 - minimumSize);
150 return position;
151}
152
154{
155 const qreal effectiveStep = stepSize * (1.0 - size);
156 if (qFuzzyIsNull(effectiveStep))
157 return position;
158
159 return qRound(position / effectiveStep) * effectiveStep;
160}
161
163{
164 Q_Q(const QQuickScrollBar);
166 return logicalPosition(point.x() - q->leftPadding()) / q->availableWidth();
167 else
168 return logicalPosition(point.y() - q->topPadding()) / q->availableHeight();
169}
170
172{
173 Q_Q(QQuickScrollBar);
174 if (interactive == enabled)
175 return;
176
178 if (interactive) {
179 q->setAcceptedMouseButtons(Qt::LeftButton);
180#if QT_CONFIG(quicktemplates2_multitouch)
181 q->setAcceptTouchEvents(true);
182#endif
183#if QT_CONFIG(cursor)
184 q->setCursor(Qt::ArrowCursor);
185#endif
186 } else {
187 q->setAcceptedMouseButtons(Qt::NoButton);
188#if QT_CONFIG(quicktemplates2_multitouch)
189 q->setAcceptTouchEvents(false);
190#endif
191#if QT_CONFIG(cursor)
192 q->unsetCursor();
193#endif
194 q->ungrabMouse();
195 }
196 emit q->interactiveChanged();
197}
198
200{
201 Q_Q(QQuickScrollBar);
202#if QT_CONFIG(quicktemplates2_hover)
203 bool hover = hovered;
204#else
205 bool hover = false;
206#endif
207 q->setActive(moving || (interactive && (pressed || hover)));
208}
209
211{
212 Q_Q(QQuickScrollBar);
213 if (!contentItem)
214 return;
215
216 // - negative overshoot (pos < 0): clamp the pos to 0, and deduct the overshoot from the size
217 // - positive overshoot (pos + size > 1): clamp the size to 1-pos
218 const VisualArea visual = visualArea();
219
221 contentItem->setPosition(QPointF(q->leftPadding() + visual.position * q->availableWidth(), q->topPadding()));
222 contentItem->setSize(QSizeF(q->availableWidth() * visual.size, q->availableHeight()));
223 } else {
224 contentItem->setPosition(QPointF(q->leftPadding(), q->topPadding() + visual.position * q->availableHeight()));
225 contentItem->setSize(QSizeF(q->availableWidth(), q->availableHeight() * visual.size));
226 }
227}
228
230{
231 Q_Q(QQuickScrollBar);
233 QQuickIndicatorButton *indicatorButton = q->decreaseVisual();
234 if (!indicatorButton || item != indicatorButton->indicator()) {
235 indicatorButton = q->increaseVisual();
236 if (!indicatorButton || item != indicatorButton->indicator())
237 return;
238 }
239 if (indicatorButton)
240 emit indicatorButton->implicitIndicatorWidthChanged();
241}
242
244{
245 Q_Q(QQuickScrollBar);
247 QQuickIndicatorButton *indicatorButton = q->decreaseVisual();
248 if (!indicatorButton || item != indicatorButton->indicator()) {
249 indicatorButton = q->increaseVisual();
250 if (!indicatorButton || item != indicatorButton->indicator())
251 return;
252 }
253 if (indicatorButton)
254 emit indicatorButton->implicitIndicatorHeightChanged();
255}
256
258{
259 Q_Q(QQuickScrollBar);
260 QQuickControlPrivate::handlePress(point, timestamp);
261 if (QQuickIndicatorButton *indicatorButton = q->decreaseVisual()) {
262 QQuickItem *decreaseArrow = indicatorButton->indicator();
263 if (decreaseArrow && decreaseArrow->contains(q->mapToItem(decreaseArrow, point + QPointF(0.5, 0.5)))) {
264 indicatorButton->setPressed(true);
265 q->decrease();
266 return true;
267 }
268 }
269
270 if (QQuickIndicatorButton *increaseObject = q->increaseVisual()) {
271 QQuickItem *increaseArrow = increaseObject->indicator();
272 if (increaseArrow && increaseArrow->contains(q->mapToItem(increaseArrow, point + QPointF(0.5, 0.5)))) {
273 increaseObject->setPressed(true);
274 q->increase();
275 return true;
276 }
277 }
278
279 offset = positionAt(point) - position;
281 if (offset < 0 || offset > sz)
282 offset = sz / 2;
283 q->setPressed(true);
284 return true;
285}
286
288{
289 Q_Q(QQuickScrollBar);
290 QQuickControlPrivate::handleMove(point, timestamp);
291
292 /*
293 * handleMove() will be called as soon as you hold the mouse button down *anywhere* on the
294 * ScrollBar, including the increase/decrease button indicator areas. So without the following
295 * early return, it would move the scrollbar handle to one of its extremeties. That would
296 * ruin the behavior we would like when clicking e.g. the "increase button": To step the
297 * scrollbar gently.
298 */
299 if (!pressed)
300 return true;
301
302 qreal pos = qMax<qreal>(0.0, qMin<qreal>(positionAt(point) - offset, 1.0 - size));
305 q->setPosition(pos);
306 return true;
307}
308
310{
311 Q_Q(QQuickScrollBar);
312 QQuickControlPrivate::handleRelease(point, timestamp);
313
314 if (orientation == Qt::Vertical) {
315 if (point.y() < q->topPadding() || point.y() >= (q->height() - q->bottomPadding()))
316 return true;
317 } else /* orientation == Qt::Horizontal */{
318 if (point.x() < q->leftPadding() || point.x() >= (q->width() - q->rightPadding()))
319 return true;
320 }
321
322 qreal pos = qMax<qreal>(0.0, qMin<qreal>(positionAt(point) - offset, 1.0 - size));
325 q->setPosition(pos);
326 offset = 0.0;
327 q->setPressed(false);
328 return true;
329}
330
332{
333 Q_Q(QQuickScrollBar);
335 offset = 0.0;
336 q->setPressed(false);
337}
338
339void QQuickScrollBarPrivate::visualAreaChange(const VisualArea &newVisualArea, const VisualArea &oldVisualArea)
340{
341 Q_Q(QQuickScrollBar);
342 if (!qFuzzyCompare(newVisualArea.size, oldVisualArea.size))
343 emit q->visualSizeChanged();
344 if (!qFuzzyCompare(newVisualArea.position, oldVisualArea.position))
345 emit q->visualPositionChanged();
346}
347
348void QQuickScrollBarPrivate::updateHover(const QPointF &pos, std::optional<bool> newHoverState)
349{
350 Q_Q(QQuickScrollBar);
351 auto updateHoverOnButton = [&](QQuickIndicatorButton *sbButton) {
352 if (sbButton) {
353 bool hovered = newHoverState.value_or(false);
354 if (!newHoverState.has_value()) {
355 if (QQuickItem *indicator = sbButton->indicator())
356 hovered = indicator->contains(q->mapToItem(indicator, pos));
357 }
358 sbButton->setHovered(hovered);
359 }
360 };
361 updateHoverOnButton(q->decreaseVisual());
362 updateHoverOnButton(q->increaseVisual());
363}
364
366 : QQuickControl(*(new QQuickScrollBarPrivate), parent)
367{
368 Q_D(QQuickScrollBar);
369 d->decreaseVisual = new QQuickIndicatorButton(this);
370 d->increaseVisual = new QQuickIndicatorButton(this);
372 setKeepMouseGrab(true);
374#if QT_CONFIG(quicktemplates2_multitouch)
376#endif
377#if QT_CONFIG(cursor)
379#endif
380}
381
386
400{
401 Q_D(const QQuickScrollBar);
402 return d->size;
403}
404
406{
407 Q_D(QQuickScrollBar);
408 if (!qt_is_finite(size))
409 return;
410 size = qBound(0.0, size, 1.0);
411 if (qFuzzyCompare(d->size, size))
412 return;
413
414 const auto oldVisualArea = d->visualArea();
415 d->size = size;
416 if (d->size + d->position > 1.0) {
417 d->setPosition(1.0 - d->size, false);
418 }
419
421 d->resizeContent();
423 d->visualAreaChange(d->visualArea(), oldVisualArea);
424}
425
444{
445 Q_D(const QQuickScrollBar);
446 return d->position;
447}
448
450{
451 Q_D(QQuickScrollBar);
452 d->setPosition(position);
453}
454
455void QQuickScrollBarPrivate::setPosition(qreal newPosition, bool notifyVisualChange)
456{
457 Q_Q(QQuickScrollBar);
458 if (!qt_is_finite(newPosition) || qFuzzyCompare(position, newPosition))
459 return;
460
461 auto oldVisualArea = visualArea();
462 position = newPosition;
463 if (q->isComponentComplete())
465 emit q->positionChanged();
466 if (notifyVisualChange)
467 visualAreaChange(visualArea(), oldVisualArea);
468}
469
478{
479 Q_D(const QQuickScrollBar);
480 return d->stepSize;
481}
482
484{
485 Q_D(QQuickScrollBar);
486 if (!qt_is_finite(step) || qFuzzyCompare(d->stepSize, step))
487 return;
488
489 d->stepSize = step;
491}
492
506{
507 Q_D(const QQuickScrollBar);
508 return d->active;
509}
510
512{
513 Q_D(QQuickScrollBar);
514 if (d->active == active)
515 return;
516
517 d->active = active;
519}
520
527{
528 Q_D(const QQuickScrollBar);
529 return d->pressed;
530}
531
533{
534 Q_D(QQuickScrollBar);
535 if (!pressed) {
537 button->setPressed(false);
539 button->setPressed(false);
540 }
541 if (d->pressed == pressed)
542 return;
543
544 d->pressed = pressed;
545 setAccessibleProperty("pressed", pressed);
546 d->updateActive();
548}
549
565{
566 Q_D(const QQuickScrollBar);
567 return d->orientation;
568}
569
571{
572 Q_D(QQuickScrollBar);
573 if (d->orientation == orientation)
574 return;
575
578 else
580
581 d->orientation = orientation;
583 d->resizeContent();
585}
586
612{
613 Q_D(const QQuickScrollBar);
614 return d->snapMode;
615}
616
618{
619 Q_D(QQuickScrollBar);
620 if (d->snapMode == mode)
621 return;
622
623 d->snapMode = mode;
624 emit snapModeChanged();
625}
626
638{
639 Q_D(const QQuickScrollBar);
640 return d->interactive;
641}
642
644{
645 Q_D(QQuickScrollBar);
646 d->explicitInteractive = true;
647 d->setInteractive(interactive);
648}
649
651{
652 Q_D(QQuickScrollBar);
653 d->explicitInteractive = false;
654 d->setInteractive(true);
655}
656
683{
684 Q_D(const QQuickScrollBar);
685 return d->policy;
686}
687
689{
690 Q_D(QQuickScrollBar);
691 if (d->policy == policy)
692 return;
693
694 d->policy = policy;
695 emit policyChanged();
696}
697
708{
709 Q_D(const QQuickScrollBar);
710 return d->orientation == Qt::Horizontal;
711}
712
723{
724 Q_D(const QQuickScrollBar);
725 return d->orientation == Qt::Vertical;
726}
727
737{
738 Q_D(const QQuickScrollBar);
739 return d->minimumSize;
740}
741
743{
744 Q_D(QQuickScrollBar);
745 if (!qt_is_finite(minimumSize) || qFuzzyCompare(d->minimumSize, minimumSize))
746 return;
747
748 auto oldVisualArea = d->visualArea();
749 d->minimumSize = qBound(0.0, minimumSize, 1.0);
751 d->resizeContent();
752 emit minimumSizeChanged();
753 d->visualAreaChange(d->visualArea(), oldVisualArea);
754}
755
767{
768 Q_D(const QQuickScrollBar);
769 return d->visualArea().size;
770}
771
783{
784 Q_D(const QQuickScrollBar);
785 return d->visualArea().position;
786}
787
789{
790 Q_D(QQuickScrollBar);
791 return d->decreaseVisual;
792}
793
795{
796 Q_D(QQuickScrollBar);
797 return d->increaseVisual;
798}
799
808{
809 Q_D(QQuickScrollBar);
810 qreal step = qFuzzyIsNull(d->stepSize) ? 0.1 : d->stepSize;
811 bool wasActive = d->active;
812 setActive(true);
813 setPosition(qMin<qreal>(1.0 - d->size, d->position + step));
814 setActive(wasActive);
815}
816
825{
826 Q_D(QQuickScrollBar);
827 qreal step = qFuzzyIsNull(d->stepSize) ? 0.1 : d->stepSize;
828 bool wasActive = d->active;
829 setActive(true);
830 setPosition(qMax<qreal>(0.0, d->position - step));
831 setActive(wasActive);
832}
833
835{
836 Q_D(QQuickScrollBar);
838 d->handleMove(event->position(), event->timestamp());
839}
840
841#if QT_CONFIG(quicktemplates2_hover)
842void QQuickScrollBar::hoverChange()
843{
844 Q_D(QQuickScrollBar);
845 d->updateActive();
846}
847
849{
850 Q_D(QQuickScrollBar);
852 d->updateHover(event->position());
853 event->ignore();
854}
855
857{
858 Q_D(QQuickScrollBar);
860 d->updateHover(event->position());
861 event->ignore();
862}
863
865{
866 Q_D(QQuickScrollBar);
868
869 d->updateHover(QPoint(), false); //position is not needed when we force it to unhover
870 event->ignore();
871}
872#endif
873
875{
876 Q_D(QQuickScrollBar);
878
880 if (context) {
881 QQmlEngine::setContextForObject(d->decreaseVisual, context);
882 QQmlEngine::setContextForObject(d->increaseVisual, context);
883 }
884}
885
887{
888 Q_D(QQuickScrollBar);
889 QQuickIndicatorButtonPrivate::get(d->decreaseVisual)->executeIndicator(true);
890 QQuickIndicatorButtonPrivate::get(d->increaseVisual)->executeIndicator(true);
891
893}
894
895#if QT_CONFIG(accessibility)
896void QQuickScrollBar::accessibilityActiveChanged(bool active)
897{
898 QQuickControl::accessibilityActiveChanged(active);
899
900 Q_D(QQuickScrollBar);
901 if (active) {
902 setAccessibleProperty("pressed", d->pressed);
903
904 if (QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(this)) {
905 connect(accessibleAttached, &QQuickAccessibleAttached::increaseAction, this, &QQuickScrollBar::increase);
906 connect(accessibleAttached, &QQuickAccessibleAttached::decreaseAction, this, &QQuickScrollBar::decrease);
907 }
908 } else {
909 if (QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(this)) {
910 disconnect(accessibleAttached, &QQuickAccessibleAttached::increaseAction, this, &QQuickScrollBar::increase);
911 disconnect(accessibleAttached, &QQuickAccessibleAttached::decreaseAction, this, &QQuickScrollBar::decrease);
912 }
913 }
914}
915
916QAccessible::Role QQuickScrollBar::accessibleRole() const
917{
918 return QAccessible::ScrollBar;
919}
920#endif
921
923{
924 if (flickable) {
925 // NOTE: Use removeItemChangeListener(Geometry) instead of updateOrRemoveGeometryChangeListener(Size).
926 // The latter doesn't remove the listener but only resets its types. Thus, it leaves behind a dangling
927 // pointer on destruction.
928 QQuickItemPrivate::get(flickable)->removeItemChangeListener(this, QQuickItemPrivate::Geometry);
929 QQuickItemPrivate::get(flickable)->removeItemChangeListener(this, QQuickItemPrivate::Destroyed);
930 if (horizontal)
932 if (vertical)
934 }
935
936 flickable = item;
937
938 if (item) {
939 // Don't know how to combine these calls into one, and as long as they're separate calls,
940 // the remove* calls above need to be separate too, otherwise they will have no effect.
941 QQuickItemPrivate::get(item)->updateOrAddGeometryChangeListener(this, QQuickGeometryChange::Size);
942 QQuickItemPrivate::get(item)->updateOrAddItemChangeListener(this, QQuickItemPrivate::Destroyed);
943 if (horizontal)
945 if (vertical)
946 initVertical();
947 }
948}
949
951{
953
955
956 // TODO: export QQuickFlickableVisibleArea
957 QObject *area = flickable->property("visibleArea").value<QObject *>();
958 QObject::connect(area, SIGNAL(widthRatioChanged(qreal)), horizontal, SLOT(setSize(qreal)));
960
961 // ensure that the ScrollBar is stacked above the Flickable in a ScrollView
963 if (parent && parent == flickable->parentItem())
965
966 // If a scroll bar was previously hidden (due to e.g. setting a new contentItem
967 // on a ScrollView), we need to make sure that we un-hide it.
968 if (auto control = qobject_cast<QQuickControl*>(q_func()->parent())) {
969 const auto visibility = horizontal->policy() != QQuickScrollBar::AlwaysOff
972 }
973
975 horizontal->setSize(area->property("widthRatio").toReal());
976 horizontal->setPosition(area->property("xPosition").toReal());
977}
978
980{
982
984
985 // TODO: export QQuickFlickableVisibleArea
986 QObject *area = flickable->property("visibleArea").value<QObject *>();
987 QObject::connect(area, SIGNAL(heightRatioChanged(qreal)), vertical, SLOT(setSize(qreal)));
989
990 // ensure that the ScrollBar is stacked above the Flickable in a ScrollView
992 if (parent && parent == flickable->parentItem())
994
995 if (auto control = qobject_cast<QQuickControl*>(q_func()->parent())) {
996 const auto visibility = vertical->policy() != QQuickScrollBar::AlwaysOff
998 QQuickControlPrivate::unhideOldItem(control, vertical, visibility);
999 }
1000
1002 vertical->setSize(area->property("heightRatio").toReal());
1003 vertical->setPosition(area->property("yPosition").toReal());
1004}
1005
1007{
1009
1011 // ScrollBar.qml has a binding to visible and ScrollView.qml has a binding to parent.
1012 // If we just set visible to false and parent to null, these bindings will overwrite
1013 // them upon component completion as part of the binding evaluation.
1014 // That's why we remove the binding completely.
1015 const QQmlProperty visibleProperty(horizontal, QStringLiteral("visible"));
1016 const QQmlProperty parentProperty(horizontal, QStringLiteral("parent"));
1017 QQmlPropertyPrivate::removeBinding(visibleProperty);
1018 QQmlPropertyPrivate::removeBinding(parentProperty);
1019
1021
1022 // TODO: export QQuickFlickableVisibleArea
1023 QObject *area = flickable->property("visibleArea").value<QObject *>();
1024 QObject::disconnect(area, SIGNAL(widthRatioChanged(qreal)), horizontal, SLOT(setSize(qreal)));
1026}
1027
1029{
1031
1033 const QQmlProperty visibleProperty(vertical, QStringLiteral("visible"));
1034 const QQmlProperty parentProperty(vertical, QStringLiteral("parent"));
1035 QQmlPropertyPrivate::removeBinding(visibleProperty);
1036 QQmlPropertyPrivate::removeBinding(parentProperty);
1037
1039
1040 // TODO: export QQuickFlickableVisibleArea
1041 QObject *area = flickable->property("visibleArea").value<QObject *>();
1042 QObject::disconnect(area, SIGNAL(heightRatioChanged(qreal)), vertical, SLOT(setSize(qreal)));
1044}
1045
1052
1059
1060// TODO: QQuickFlickable::maxXYExtent()
1065
1067{
1068 if (!flickable)
1069 return;
1070
1072
1073 const qreal viewwidth = f->width();
1074 const qreal maxxextent = -f->maxXExtent() + f->minXExtent();
1075 const qreal cx = horizontal->position() * (maxxextent + viewwidth) - f->minXExtent();
1076
1077 if (!qIsNaN(cx) && !qFuzzyCompare(cx, flickable->contentX()))
1079}
1080
1082{
1083 if (!flickable)
1084 return;
1085
1087
1088 const qreal viewheight = f->height();
1089 const qreal maxyextent = -f->maxYExtent() + f->minYExtent();
1090 const qreal cy = vertical->position() * (maxyextent + viewheight) - f->minYExtent();
1091
1092 if (!qIsNaN(cy) && !qFuzzyCompare(cy, flickable->contentY()))
1094}
1095
1100
1102{
1105 return;
1107 if (move)
1109}
1110
1112{
1114 if (vertical->parentItem() != flickable)
1115 return;
1117 if (move)
1119}
1120
1122{
1123 Q_UNUSED(item);
1124 Q_UNUSED(change);
1125 if (horizontal && horizontal->height() > 0) {
1126#ifdef QT_QUICK_NEW_GEOMETRY_CHANGED_HANDLING // TODO: correct/rename diff to oldGeometry
1127 bool move = qFuzzyIsNull(horizontal->y()) || qFuzzyCompare(horizontal->y(), diff.height() - horizontal->height());
1128#else
1129 bool move = qFuzzyIsNull(horizontal->y()) || qFuzzyCompare(horizontal->y(), item->height() - diff.height() - horizontal->height());
1130#endif
1131 if (flickable)
1132 layoutHorizontal(move);
1133 }
1134 if (vertical && vertical->width() > 0) {
1135#ifdef QT_QUICK_NEW_GEOMETRY_CHANGED_HANDLING // TODO: correct/rename diff to oldGeometry
1136 bool move = qFuzzyIsNull(vertical->x()) || qFuzzyCompare(vertical->x(), diff.width() - vertical->width());
1137#else
1138 bool move = qFuzzyIsNull(vertical->x()) || qFuzzyCompare(vertical->x(), item->width() - diff.width() - vertical->width());
1139#endif
1140 if (flickable)
1141 layoutVertical(move);
1142 }
1143}
1144
1150
1156
1158{
1159 if (item == flickable)
1160 flickable = nullptr;
1161 if (item == horizontal)
1162 horizontal = nullptr;
1163 if (item == vertical)
1164 vertical = nullptr;
1165}
1166
1169{
1171 d->setFlickable(qobject_cast<QQuickFlickable *>(parent));
1172
1173 if (parent && !d->flickable && !qobject_cast<QQuickScrollView *>(parent))
1174 qmlWarning(parent) << "ScrollBar must be attached to a Flickable or ScrollView";
1175}
1176
1178{
1180 if (d->horizontal) {
1181 QQuickItemPrivate::get(d->horizontal)->removeItemChangeListener(d, QsbHorizontalChangeTypes);
1182 d->horizontal = nullptr;
1183 }
1184 if (d->vertical) {
1185 QQuickItemPrivate::get(d->vertical)->removeItemChangeListener(d, QsbVerticalChangeTypes);
1186 d->vertical = nullptr;
1187 }
1188 d->setFlickable(nullptr);
1189}
1190
1206{
1207 Q_D(const QQuickScrollBarAttached);
1208 return d->horizontal;
1209}
1210
1212{
1214 if (d->horizontal == horizontal)
1215 return;
1216
1217 if (d->horizontal) {
1218 QQuickItemPrivate::get(d->horizontal)->removeItemChangeListener(d, QsbHorizontalChangeTypes);
1220
1221 if (d->flickable)
1222 d->cleanupHorizontal();
1223 }
1224
1225 d->horizontal = horizontal;
1226
1227 if (horizontal) {
1228 if (!horizontal->parentItem())
1229 horizontal->setParentItem(qobject_cast<QQuickItem *>(parent()));
1231
1234
1235 if (d->flickable)
1236 d->initHorizontal();
1237 }
1239}
1240
1256{
1257 Q_D(const QQuickScrollBarAttached);
1258 return d->vertical;
1259}
1260
1262{
1264 if (d->vertical == vertical)
1265 return;
1266
1267 if (d->vertical) {
1268 QQuickItemPrivate::get(d->vertical)->removeItemChangeListener(d, QsbVerticalChangeTypes);
1271
1272 if (d->flickable)
1273 d->cleanupVertical();
1274 }
1275
1276 d->vertical = vertical;
1277
1278 if (vertical) {
1279 if (!vertical->parentItem())
1280 vertical->setParentItem(qobject_cast<QQuickItem *>(parent()));
1282
1283 QQuickItemPrivate::get(vertical)->addItemChangeListener(d, QsbVerticalChangeTypes);
1286
1287 if (d->flickable)
1288 d->initVertical();
1289 }
1291}
1292
1294
1295#include "moc_qquickscrollbar_p.cpp"
\inmodule QtGui
Definition qevent.h:246
static constexpr Policy Preferred
static constexpr Policy Fixed
\inmodule QtGui
Definition qevent.h:196
QObject * parent
Definition qobject.h:73
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
Definition qobject_p.h:299
static bool disconnect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot)
Definition qobject_p.h:328
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
Definition qobject.cpp:3236
QVariant property(const char *name) const
Returns the value of the object's name property.
Definition qobject.cpp:4323
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:348
\inmodule QtCore\reentrant
Definition qpoint.h:25
The QQmlContext class defines a context within a QML engine.
Definition qqmlcontext.h:25
static void setContextForObject(QObject *, QQmlContext *)
Sets the QQmlContext for the object to context.
static void removeBinding(const QQmlProperty &that)
The QQmlProperty class abstracts accessing properties on objects created from QML.
void itemImplicitWidthChanged(QQuickItem *item) override
static void unhideOldItem(QQuickControl *control, QQuickItem *item, UnhideVisibility visibility=UnhideVisibility::Show)
virtual bool handlePress(const QPointF &point, ulong timestamp)
QQuickDeferredPointer< QQuickItem > contentItem
static void hideOldItem(QQuickItem *item)
virtual void handleUngrab()
virtual bool handleRelease(const QPointF &point, ulong timestamp)
virtual bool handleMove(const QPointF &point, ulong timestamp)
void itemImplicitHeightChanged(QQuickItem *item) override
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void mirroredChanged()
void classBegin() override
Invoked after class creation, but before any properties have been set.
void mousePressEvent(QMouseEvent *event) override
This event handler can be reimplemented in a subclass to receive mouse press events for an item.
bool setAccessibleProperty(const char *propertyName, const QVariant &value)
bool isMirrored() const
\qmlproperty bool QtQuick.Controls::Control::mirrored \readonly
bool isMovingHorizontally() const
virtual void setContentX(qreal pos)
void movingHorizontallyChanged()
virtual void setContentY(qreal pos)
void movingVerticallyChanged()
bool isMovingVertically() const
static QQuickIndicatorButtonPrivate * get(QQuickIndicatorButton *button)
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
virtual void hoverEnterEvent(QHoverEvent *event)
This event handler can be reimplemented in a subclass to receive hover-enter events for an item.
void setSize(const QSizeF &size)
qreal x
\qmlproperty real QtQuick::Item::x \qmlproperty real QtQuick::Item::y \qmlproperty real QtQuick::Item...
Definition qquickitem.h:72
void setParentItem(QQuickItem *parent)
virtual void hoverMoveEvent(QHoverEvent *event)
This event handler can be reimplemented in a subclass to receive hover-move events for an item.
qreal y
Defines the item's y position relative to its parent.
Definition qquickitem.h:73
void setAcceptTouchEvents(bool accept)
If enabled is true, this sets the item to accept touch events; otherwise, touch events are not accept...
void setHeight(qreal)
void setAcceptedMouseButtons(Qt::MouseButtons buttons)
Sets the mouse buttons accepted by this item to buttons.
qreal width
This property holds the width of this item.
Definition qquickitem.h:75
QQuickItem * parentItem() const
void stackAfter(const QQuickItem *)
Moves the specified sibling item to the index after this item within the list of children.
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
void setKeepMouseGrab(bool)
Sets whether the mouse input should remain exclusively with this item.
qreal height
This property holds the height of this item.
Definition qquickitem.h:76
void setPosition(const QPointF &)
void setWidth(qreal)
friend class QQuickAccessibleAttached
Definition qquickitem.h:479
void setX(qreal)
virtual void hoverLeaveEvent(QHoverEvent *event)
This event handler can be reimplemented in a subclass to receive hover-leave events for an item.
void setY(qreal)
void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &diff) override
void setFlickable(QQuickFlickable *flickable)
void layoutHorizontal(bool move=true)
void itemImplicitHeightChanged(QQuickItem *item) override
void itemDestroyed(QQuickItem *item) override
void itemImplicitWidthChanged(QQuickItem *item) override
void setVertical(QQuickScrollBar *vertical)
QQuickScrollBarAttached(QObject *parent=nullptr)
void setHorizontal(QQuickScrollBar *horizontal)
QQuickScrollBar * horizontal
void itemImplicitHeightChanged(QQuickItem *item) override
bool handlePress(const QPointF &point, ulong timestamp) override
qreal snapPosition(qreal position) const
static QQuickScrollBarPrivate * get(QQuickScrollBar *bar)
void itemImplicitWidthChanged(QQuickItem *item) override
void updateHover(const QPointF &pos, std::optional< bool > newHoverState={})
bool handleRelease(const QPointF &point, ulong timestamp) override
bool handleMove(const QPointF &point, ulong timestamp) override
void visualAreaChange(const VisualArea &newVisualArea, const VisualArea &oldVisualArea)
qreal positionAt(const QPointF &point) const
void setPosition(qreal position, bool notifyVisualChange=true)
void setInteractive(bool interactive)
void resizeContent() override
qreal logicalPosition(qreal position) const
QQuickScrollBar::SnapMode snapMode
VisualArea visualArea() const
void activeChanged()
bool isPressed() const
\qmlproperty bool QtQuick.Controls::ScrollBar::pressed
void increase()
\qmlmethod void QtQuick.Controls::ScrollBar::increase()
QQuickIndicatorButton * increaseVisual()
void setMinimumSize(qreal minimumSize)
void pressedChanged()
void orientationChanged()
void positionChanged()
static QQuickScrollBarAttached * qmlAttachedProperties(QObject *object)
void setActive(bool active)
void setInteractive(bool interactive)
void setPolicy(Policy policy)
QQuickIndicatorButton * decreaseVisual()
bool isHorizontal() const
void stepSizeChanged()
Qt::Orientation orientation
void setPressed(bool pressed)
void setStepSize(qreal step)
void setOrientation(Qt::Orientation orientation)
void setPosition(qreal position)
void classBegin() override
Invoked after class creation, but before any properties have been set.
QQuickScrollBar(QQuickItem *parent=nullptr)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void mousePressEvent(QMouseEvent *event) override
This event handler can be reimplemented in a subclass to receive mouse press events for an item.
void setSnapMode(SnapMode mode)
void decrease()
\qmlmethod void QtQuick.Controls::ScrollBar::decrease()
bool isInteractive() const
bool isVertical() const
bool isActive() const
\qmlproperty bool QtQuick.Controls::ScrollBar::active
void setSize(qreal size)
\inmodule QtCore\reentrant
Definition qrect.h:484
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:732
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:729
\inmodule QtCore
Definition qsize.h:208
T value() const &
Definition qvariant.h:516
QPushButton * button
[2]
Combined button and popup list for selecting options.
@ LeftButton
Definition qnamespace.h:58
@ NoButton
Definition qnamespace.h:57
Orientation
Definition qnamespace.h:98
@ Horizontal
Definition qnamespace.h:99
@ Vertical
Definition qnamespace.h:100
@ ArrowCursor
static void * context
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:333
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:349
bool qIsNaN(qfloat16 f) noexcept
Definition qfloat16.h:284
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
static int area(const QSize &s)
Definition qicon.cpp:153
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
static Q_DECL_CONST_FUNCTION bool qt_is_finite(double d)
Definition qnumeric_p.h:117
#define SLOT(a)
Definition qobjectdefs.h:52
#define SIGNAL(a)
Definition qobjectdefs.h:53
n void setPosition(void) \n\
GLenum mode
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLfloat GLfloat f
GLenum GLuint GLintptr offset
struct _cl_event * event
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
QQmlContext * qmlContext(const QObject *obj)
Definition qqml.cpp:75
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static QT_BEGIN_NAMESPACE const QQuickItemPrivate::ChangeTypes QsbChangeTypes
Vertical or horizontal interactive scroll bar.
static const QQuickItemPrivate::ChangeTypes QsbVerticalChangeTypes
static const QQuickItemPrivate::ChangeTypes QsbHorizontalChangeTypes
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QStringLiteral(str)
#define emit
#define Q_UNUSED(x)
unsigned long ulong
Definition qtypes.h:35
double qreal
Definition qtypes.h:187
#define enabled
myObject disconnect()
[26]
item setCursor(Qt::IBeamCursor)
[1]
QGraphicsItem * item
QSizePolicy policy