200 Q_Q(QQuickScrollView);
201 qreal oldEffectiveScrollBarWidth = effectiveScrollBarWidth;
202 if (
auto *vBar = verticalScrollBar()) {
203 if (vBar->policy() == QQuickScrollBar::AlwaysOff || !vBar->isVisible())
204 effectiveScrollBarWidth = 0;
206 effectiveScrollBarWidth = vBar->width();
208 if (effectiveScrollBarWidth != oldEffectiveScrollBarWidth) {
210 QScopedValueRollback<
bool> rollback(isUpdatingScrollBar,
true);
211 emit q->effectiveScrollBarWidthChanged();
218 Q_Q(QQuickScrollView);
219 qreal oldEffectiveScrollBarHeight = effectiveScrollBarHeight;
220 if (
auto *hBar = horizontalScrollBar()) {
221 if (hBar->policy() == QQuickScrollBar::AlwaysOff || !hBar->isVisible())
222 effectiveScrollBarHeight = 0;
224 effectiveScrollBarHeight = hBar->height();
226 if (effectiveScrollBarHeight != oldEffectiveScrollBarHeight) {
228 QScopedValueRollback<
bool> rollback(isUpdatingScrollBar,
true);
229 emit q->effectiveScrollBarHeightChanged();
240 if (scrollBar->vertical) {
241 QObjectPrivate::disconnect(scrollBar->vertical, &QQuickScrollBar::policyChanged,
this, &QQuickScrollViewPrivate::updateScrollBarWidth);
242 QObjectPrivate::disconnect(scrollBar->vertical, &QQuickScrollBar::visibleChanged,
this, &QQuickScrollViewPrivate::updateScrollBarWidth);
244 if (scrollBar->horizontal) {
245 QObjectPrivate::disconnect(scrollBar->horizontal, &QQuickScrollBar::policyChanged,
this, &QQuickScrollViewPrivate::updateScrollBarHeight);
246 QObjectPrivate::disconnect(scrollBar->horizontal, &QQuickScrollBar::visibleChanged,
this, &QQuickScrollViewPrivate::updateScrollBarHeight);
252 Q_Q(QQuickScrollView);
256 QQuickScrollBarAttached *attached = qobject_cast<QQuickScrollBarAttached *>(qmlAttachedPropertiesObject<QQuickScrollBar>(q,
false));
262 auto *scrollBar = QQuickScrollBarAttachedPrivate::get(attached);
263 scrollBar->setFlickable(
nullptr);
267 QObjectPrivate::disconnect(flickable->contentItem(), &QQuickItem::childrenChanged,
this, &QQuickPanePrivate::contentChildrenChange);
268 QObjectPrivate::disconnect(flickable, &QQuickFlickable::contentWidthChanged,
this, &QQuickScrollViewPrivate::flickableContentWidthChanged);
269 QObjectPrivate::disconnect(flickable, &QQuickFlickable::contentHeightChanged,
this, &QQuickScrollViewPrivate::flickableContentHeightChanged);
273 if (contentItemFlag == ContentItemFlag::Set)
274 q->setContentItem(flickable);
279 flickable->setContentWidth(contentWidth);
282 if (hasContentHeight)
283 flickable->setContentHeight(contentHeight);
288 auto *scrollBar = QQuickScrollBarAttachedPrivate::get(attached);
290 if (scrollBar->vertical) {
291 QObjectPrivate::connect(scrollBar->vertical, &QQuickScrollBar::policyChanged,
this, &QQuickScrollViewPrivate::updateScrollBarWidth);
292 QObjectPrivate::connect(scrollBar->vertical, &QQuickScrollBar::visibleChanged,
this, &QQuickScrollViewPrivate::updateScrollBarWidth);
294 if (scrollBar->horizontal) {
295 QObjectPrivate::connect(scrollBar->horizontal, &QQuickScrollBar::policyChanged,
this, &QQuickScrollViewPrivate::updateScrollBarHeight);
296 QObjectPrivate::connect(scrollBar->horizontal, &QQuickScrollBar::visibleChanged,
this, &QQuickScrollViewPrivate::updateScrollBarHeight);
300 QObjectPrivate::connect(flickable->contentItem(), &QQuickItem::childrenChanged,
this, &QQuickPanePrivate::contentChildrenChange);
301 QObjectPrivate::connect(flickable, &QQuickFlickable::contentWidthChanged,
this, &QQuickScrollViewPrivate::flickableContentWidthChanged);
302 QObjectPrivate::connect(flickable, &QQuickFlickable::contentHeightChanged,
this, &QQuickScrollViewPrivate::flickableContentHeightChanged);
563 Q_Q(QQuickScrollView);
564 return QQmlListProperty<QObject>(q,
this,
565 QQuickScrollViewPrivate::contentData_append,
566 QQuickScrollViewPrivate::contentData_count,
567 QQuickScrollViewPrivate::contentData_at,
568 QQuickScrollViewPrivate::contentData_clear);
584 Q_Q(QQuickScrollView);
585 return QQmlListProperty<QQuickItem>(q,
this,
586 QQuickScrollViewPrivate::contentChildren_append,
587 QQuickScrollViewPrivate::contentChildren_count,
588 QQuickScrollViewPrivate::contentChildren_at,
589 QQuickScrollViewPrivate::contentChildren_clear);
592bool QQuickScrollView::childMouseEventFilter(QQuickItem *item, QEvent *event)
594 Q_D(QQuickScrollView);
595 switch (event->type()) {
596 case QEvent::TouchBegin:
597 d->wasTouched =
true;
598 d->setScrollBarsInteractive(
false);
601 case QEvent::TouchEnd:
602 d->wasTouched =
false;
605 case QEvent::MouseButtonPress:
607 if (
static_cast<QMouseEvent *>(event)->source() == Qt::MouseEventNotSynthesized) {
608 d->wasTouched =
false;
609 d->setScrollBarsInteractive(
true);
612 return !d->wasTouched && item == d->flickable;
614 case QEvent::MouseMove:
615 case QEvent::MouseButtonRelease:
616 if (
static_cast<QMouseEvent *>(event)->source() == Qt::MouseEventNotSynthesized)
617 return item == d->flickable;
620 case QEvent::HoverEnter:
621 case QEvent::HoverMove:
622 if (d->wasTouched && (item == d->verticalScrollBar() || item == d->horizontalScrollBar()))
623 d->setScrollBarsInteractive(
true);
633bool QQuickScrollView::eventFilter(QObject *object, QEvent *event)
635 Q_D(QQuickScrollView);
636 if (event->type() == QEvent::Wheel) {
637 d->setScrollBarsInteractive(
true);
638 if (!d->wheelEnabled) {
643 return QQuickPane::eventFilter(object, event);
646void QQuickScrollView::keyPressEvent(QKeyEvent *event)
648 Q_D(QQuickScrollView);
649 QQuickPane::keyPressEvent(event);
650 switch (event->key()) {
652 if (QQuickScrollBar *vbar = d->verticalScrollBar()) {
658 if (QQuickScrollBar *vbar = d->verticalScrollBar()) {
664 if (QQuickScrollBar *hbar = d->horizontalScrollBar()) {
670 if (QQuickScrollBar *hbar = d->horizontalScrollBar()) {
689void QQuickScrollView::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem)
691 Q_D(QQuickScrollView);
692 if (newItem != d->flickable) {
695 d->flickableHasExplicitContentWidth =
true;
696 d->flickableHasExplicitContentHeight =
true;
697 auto newItemAsFlickable = qobject_cast<QQuickFlickable *>(newItem);
698 if (newItem && !newItemAsFlickable)
699 qmlWarning(
this) <<
"ScrollView only supports Flickable types as its contentItem";
702 d->setFlickable(newItemAsFlickable, QQuickScrollViewPrivate::ContentItemFlag::DoNotSet);
708 newItem->setParentItem(
this);
712 QQuickScrollBar *verticalBar = d->verticalScrollBar();
714 verticalBar->stackAfter(newItem);
715 QQuickScrollBar *horizontalBar = d->horizontalScrollBar();
717 horizontalBar->stackAfter(newItem);
720 QQuickPane::contentItemChange(newItem, oldItem);
723void QQuickScrollView::contentSizeChange(
const QSizeF &newSize,
const QSizeF &oldSize)
725 Q_D(QQuickScrollView);
726 QQuickPane::contentSizeChange(newSize, oldSize);
734 if (d->hasContentWidth || !d->flickableHasExplicitContentWidth) {
735 d->flickable->setContentWidth(newSize.width());
736 d->updateScrollBarWidth();
738 if (d->hasContentHeight || !d->flickableHasExplicitContentHeight) {
739 d->flickable->setContentHeight(newSize.height());
740 d->updateScrollBarHeight();