197 Q_Q(QQuickScrollView);
198 qreal oldEffectiveScrollBarWidth = effectiveScrollBarWidth;
199 if (
auto *vBar = verticalScrollBar()) {
200 if (vBar->policy() == QQuickScrollBar::AlwaysOff || !vBar->isVisible())
201 effectiveScrollBarWidth = 0;
203 effectiveScrollBarWidth = vBar->width();
205 if (effectiveScrollBarWidth != oldEffectiveScrollBarWidth) {
207 QScopedValueRollback<
bool> rollback(isUpdatingScrollBar,
true);
208 emit q->effectiveScrollBarWidthChanged();
215 Q_Q(QQuickScrollView);
216 qreal oldEffectiveScrollBarHeight = effectiveScrollBarHeight;
217 if (
auto *hBar = horizontalScrollBar()) {
218 if (hBar->policy() == QQuickScrollBar::AlwaysOff || !hBar->isVisible())
219 effectiveScrollBarHeight = 0;
221 effectiveScrollBarHeight = hBar->height();
223 if (effectiveScrollBarHeight != oldEffectiveScrollBarHeight) {
225 QScopedValueRollback<
bool> rollback(isUpdatingScrollBar,
true);
226 emit q->effectiveScrollBarHeightChanged();
237 if (scrollBar->vertical) {
238 QObjectPrivate::disconnect(scrollBar->vertical, &QQuickScrollBar::policyChanged,
this, &QQuickScrollViewPrivate::updateScrollBarWidth);
239 QObjectPrivate::disconnect(scrollBar->vertical, &QQuickScrollBar::visibleChanged,
this, &QQuickScrollViewPrivate::updateScrollBarWidth);
241 if (scrollBar->horizontal) {
242 QObjectPrivate::disconnect(scrollBar->horizontal, &QQuickScrollBar::policyChanged,
this, &QQuickScrollViewPrivate::updateScrollBarHeight);
243 QObjectPrivate::disconnect(scrollBar->horizontal, &QQuickScrollBar::visibleChanged,
this, &QQuickScrollViewPrivate::updateScrollBarHeight);
249 Q_Q(QQuickScrollView);
253 QQuickScrollBarAttached *attached = qobject_cast<QQuickScrollBarAttached *>(qmlAttachedPropertiesObject<QQuickScrollBar>(q,
false));
256 flickable->removeEventFilter(q);
259 auto *scrollBar = QQuickScrollBarAttachedPrivate::get(attached);
260 scrollBar->setFlickable(
nullptr);
264 QObjectPrivate::disconnect(flickable->contentItem(), &QQuickItem::childrenChanged,
this, &QQuickPanePrivate::contentChildrenChange);
265 QObjectPrivate::disconnect(flickable, &QQuickFlickable::contentWidthChanged,
this, &QQuickScrollViewPrivate::flickableContentWidthChanged);
266 QObjectPrivate::disconnect(flickable, &QQuickFlickable::contentHeightChanged,
this, &QQuickScrollViewPrivate::flickableContentHeightChanged);
270 if (contentItemFlag == ContentItemFlag::Set)
271 q->setContentItem(flickable);
274 flickable->installEventFilter(q);
276 flickable->setContentWidth(contentWidth);
279 if (hasContentHeight)
280 flickable->setContentHeight(contentHeight);
285 auto *scrollBar = QQuickScrollBarAttachedPrivate::get(attached);
287 if (scrollBar->vertical) {
288 QObjectPrivate::connect(scrollBar->vertical, &QQuickScrollBar::policyChanged,
this, &QQuickScrollViewPrivate::updateScrollBarWidth);
289 QObjectPrivate::connect(scrollBar->vertical, &QQuickScrollBar::visibleChanged,
this, &QQuickScrollViewPrivate::updateScrollBarWidth);
291 if (scrollBar->horizontal) {
292 QObjectPrivate::connect(scrollBar->horizontal, &QQuickScrollBar::policyChanged,
this, &QQuickScrollViewPrivate::updateScrollBarHeight);
293 QObjectPrivate::connect(scrollBar->horizontal, &QQuickScrollBar::visibleChanged,
this, &QQuickScrollViewPrivate::updateScrollBarHeight);
297 QObjectPrivate::connect(flickable->contentItem(), &QQuickItem::childrenChanged,
this, &QQuickPanePrivate::contentChildrenChange);
298 QObjectPrivate::connect(flickable, &QQuickFlickable::contentWidthChanged,
this, &QQuickScrollViewPrivate::flickableContentWidthChanged);
299 QObjectPrivate::connect(flickable, &QQuickFlickable::contentHeightChanged,
this, &QQuickScrollViewPrivate::flickableContentHeightChanged);
560 Q_Q(QQuickScrollView);
561 return QQmlListProperty<QObject>(q,
this,
562 QQuickScrollViewPrivate::contentData_append,
563 QQuickScrollViewPrivate::contentData_count,
564 QQuickScrollViewPrivate::contentData_at,
565 QQuickScrollViewPrivate::contentData_clear);
589bool QQuickScrollView::childMouseEventFilter(QQuickItem *item, QEvent *event)
591 Q_D(QQuickScrollView);
592 switch (event->type()) {
593 case QEvent::TouchBegin:
594 d->wasTouched =
true;
595 d->setScrollBarsInteractive(
false);
598 case QEvent::TouchEnd:
599 d->wasTouched =
false;
602 case QEvent::MouseButtonPress:
604 if (
static_cast<QMouseEvent *>(event)->source() == Qt::MouseEventNotSynthesized) {
605 d->wasTouched =
false;
606 d->setScrollBarsInteractive(
true);
609 return !d->wasTouched && item == d->flickable;
611 case QEvent::MouseMove:
612 case QEvent::MouseButtonRelease:
613 if (
static_cast<QMouseEvent *>(event)->source() == Qt::MouseEventNotSynthesized)
614 return item == d->flickable;
617 case QEvent::HoverEnter:
618 case QEvent::HoverMove:
619 if (d->wasTouched && (item == d->verticalScrollBar() || item == d->horizontalScrollBar()))
620 d->setScrollBarsInteractive(
true);
643void QQuickScrollView::keyPressEvent(QKeyEvent *event)
645 Q_D(QQuickScrollView);
646 QQuickPane::keyPressEvent(event);
647 switch (event->key()) {
649 if (QQuickScrollBar *vbar = d->verticalScrollBar()) {
655 if (QQuickScrollBar *vbar = d->verticalScrollBar()) {
661 if (QQuickScrollBar *hbar = d->horizontalScrollBar()) {
667 if (QQuickScrollBar *hbar = d->horizontalScrollBar()) {
686void QQuickScrollView::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem)
688 Q_D(QQuickScrollView);
689 if (newItem != d->flickable) {
692 d->flickableHasExplicitContentWidth =
true;
693 d->flickableHasExplicitContentHeight =
true;
694 auto newItemAsFlickable = qobject_cast<QQuickFlickable *>(newItem);
695 if (newItem && !newItemAsFlickable)
696 qmlWarning(
this) <<
"ScrollView only supports Flickable types as its contentItem";
699 d->setFlickable(newItemAsFlickable, QQuickScrollViewPrivate::ContentItemFlag::DoNotSet);
705 newItem->setParentItem(
this);
709 QQuickScrollBar *verticalBar = d->verticalScrollBar();
711 verticalBar->stackAfter(newItem);
712 QQuickScrollBar *horizontalBar = d->horizontalScrollBar();
714 horizontalBar->stackAfter(newItem);
717 QQuickPane::contentItemChange(newItem, oldItem);
720void QQuickScrollView::contentSizeChange(
const QSizeF &newSize,
const QSizeF &oldSize)
722 Q_D(QQuickScrollView);
723 QQuickPane::contentSizeChange(newSize, oldSize);
731 if (d->hasContentWidth || !d->flickableHasExplicitContentWidth) {
732 d->flickable->setContentWidth(newSize.width());
733 d->updateScrollBarWidth();
735 if (d->hasContentHeight || !d->flickableHasExplicitContentHeight) {
736 d->flickable->setContentHeight(newSize.height());
737 d->updateScrollBarHeight();