201 Q_Q(QQuickScrollView);
202 qreal oldEffectiveScrollBarWidth = effectiveScrollBarWidth;
203 if (
auto *vBar = verticalScrollBar()) {
204 if (vBar->policy() == QQuickScrollBar::AlwaysOff || !vBar->isVisible())
205 effectiveScrollBarWidth = 0;
207 effectiveScrollBarWidth = vBar->width();
209 if (effectiveScrollBarWidth != oldEffectiveScrollBarWidth) {
211 QScopedValueRollback<
bool> rollback(isUpdatingScrollBar,
true);
212 emit q->effectiveScrollBarWidthChanged();
219 Q_Q(QQuickScrollView);
220 qreal oldEffectiveScrollBarHeight = effectiveScrollBarHeight;
221 if (
auto *hBar = horizontalScrollBar()) {
222 if (hBar->policy() == QQuickScrollBar::AlwaysOff || !hBar->isVisible())
223 effectiveScrollBarHeight = 0;
225 effectiveScrollBarHeight = hBar->height();
227 if (effectiveScrollBarHeight != oldEffectiveScrollBarHeight) {
229 QScopedValueRollback<
bool> rollback(isUpdatingScrollBar,
true);
230 emit q->effectiveScrollBarHeightChanged();
241 if (scrollBar->vertical) {
242 QObjectPrivate::disconnect(scrollBar->vertical, &QQuickScrollBar::policyChanged,
this, &QQuickScrollViewPrivate::updateScrollBarWidth);
243 QObjectPrivate::disconnect(scrollBar->vertical, &QQuickScrollBar::visibleChanged,
this, &QQuickScrollViewPrivate::updateScrollBarWidth);
244 QQuickItemPrivate::get(scrollBar->vertical)->removeItemChangeListener(
this, QQuickItemPrivate::Geometry);
246 if (scrollBar->horizontal) {
247 QObjectPrivate::disconnect(scrollBar->horizontal, &QQuickScrollBar::policyChanged,
this, &QQuickScrollViewPrivate::updateScrollBarHeight);
248 QObjectPrivate::disconnect(scrollBar->horizontal, &QQuickScrollBar::visibleChanged,
this, &QQuickScrollViewPrivate::updateScrollBarHeight);
249 QQuickItemPrivate::get(scrollBar->horizontal)->removeItemChangeListener(
this, QQuickItemPrivate::Geometry);
255 Q_Q(QQuickScrollView);
259 QQuickScrollBarAttached *attached = qobject_cast<QQuickScrollBarAttached *>(qmlAttachedPropertiesObject<QQuickScrollBar>(q,
false));
265 auto *scrollBar = QQuickScrollBarAttachedPrivate::get(attached);
266 scrollBar->setFlickable(
nullptr);
270 QObjectPrivate::disconnect(flickable->contentItem(), &QQuickItem::childrenChanged,
this, &QQuickPanePrivate::contentChildrenChange);
271 QObjectPrivate::disconnect(flickable, &QQuickFlickable::contentWidthChanged,
this, &QQuickScrollViewPrivate::flickableContentWidthChanged);
272 QObjectPrivate::disconnect(flickable, &QQuickFlickable::contentHeightChanged,
this, &QQuickScrollViewPrivate::flickableContentHeightChanged);
276 if (contentItemFlag == ContentItemFlag::Set)
277 q->setContentItem(flickable);
282 flickable->setContentWidth(contentWidth);
285 if (hasContentHeight)
286 flickable->setContentHeight(contentHeight);
291 auto *scrollBar = QQuickScrollBarAttachedPrivate::get(attached);
293 if (scrollBar->vertical) {
294 QObjectPrivate::connect(scrollBar->vertical, &QQuickScrollBar::policyChanged,
this, &QQuickScrollViewPrivate::updateScrollBarWidth);
295 QObjectPrivate::connect(scrollBar->vertical, &QQuickScrollBar::visibleChanged,
this, &QQuickScrollViewPrivate::updateScrollBarWidth);
296 QQuickItemPrivate::get(scrollBar->vertical)->addItemChangeListener(
this, QQuickItemPrivate::Geometry);
298 if (scrollBar->horizontal) {
299 QObjectPrivate::connect(scrollBar->horizontal, &QQuickScrollBar::policyChanged,
this, &QQuickScrollViewPrivate::updateScrollBarHeight);
300 QObjectPrivate::connect(scrollBar->horizontal, &QQuickScrollBar::visibleChanged,
this, &QQuickScrollViewPrivate::updateScrollBarHeight);
301 QQuickItemPrivate::get(scrollBar->horizontal)->addItemChangeListener(
this, QQuickItemPrivate::Geometry);
305 QObjectPrivate::connect(flickable->contentItem(), &QQuickItem::childrenChanged,
this, &QQuickPanePrivate::contentChildrenChange);
306 QObjectPrivate::connect(flickable, &QQuickFlickable::contentWidthChanged,
this, &QQuickScrollViewPrivate::flickableContentWidthChanged);
307 QObjectPrivate::connect(flickable, &QQuickFlickable::contentHeightChanged,
this, &QQuickScrollViewPrivate::flickableContentHeightChanged);
577 Q_Q(QQuickScrollView);
578 return QQmlListProperty<QObject>(q,
this,
579 QQuickScrollViewPrivate::contentData_append,
580 QQuickScrollViewPrivate::contentData_count,
581 QQuickScrollViewPrivate::contentData_at,
582 QQuickScrollViewPrivate::contentData_clear);
606bool QQuickScrollView::childMouseEventFilter(QQuickItem *item, QEvent *event)
608 Q_D(QQuickScrollView);
609 switch (event->type()) {
610 case QEvent::TouchBegin:
611 d->wasTouched =
true;
612 d->setScrollBarsInteractive(
false);
615 case QEvent::TouchEnd:
616 d->wasTouched =
false;
619 case QEvent::MouseButtonPress:
621 if (
static_cast<QMouseEvent *>(event)->source() == Qt::MouseEventNotSynthesized) {
622 d->wasTouched =
false;
623 d->setScrollBarsInteractive(
true);
626 return !d->wasTouched && item == d->flickable;
628 case QEvent::MouseMove:
629 case QEvent::MouseButtonRelease:
630 if (
static_cast<QMouseEvent *>(event)->source() == Qt::MouseEventNotSynthesized)
631 return item == d->flickable;
634 case QEvent::HoverEnter:
635 case QEvent::HoverMove:
636 if (d->wasTouched && (item == d->verticalScrollBar() || item == d->horizontalScrollBar()))
637 d->setScrollBarsInteractive(
true);
660void QQuickScrollView::keyPressEvent(QKeyEvent *event)
662 Q_D(QQuickScrollView);
663 QQuickPane::keyPressEvent(event);
664 switch (event->key()) {
666 if (QQuickScrollBar *vbar = d->verticalScrollBar()) {
672 if (QQuickScrollBar *vbar = d->verticalScrollBar()) {
678 if (QQuickScrollBar *hbar = d->horizontalScrollBar()) {
684 if (QQuickScrollBar *hbar = d->horizontalScrollBar()) {
703void QQuickScrollView::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem)
705 Q_D(QQuickScrollView);
706 if (newItem != d->flickable) {
709 d->flickableHasExplicitContentWidth =
true;
710 d->flickableHasExplicitContentHeight =
true;
711 auto newItemAsFlickable = qobject_cast<QQuickFlickable *>(newItem);
712 if (newItem && !newItemAsFlickable)
713 qmlWarning(
this) <<
"ScrollView only supports Flickable types as its contentItem";
716 d->setFlickable(newItemAsFlickable, QQuickScrollViewPrivate::ContentItemFlag::DoNotSet);
722 newItem->setParentItem(
this);
726 QQuickScrollBar *verticalBar = d->verticalScrollBar();
728 verticalBar->stackAfter(newItem);
729 QQuickScrollBar *horizontalBar = d->horizontalScrollBar();
731 horizontalBar->stackAfter(newItem);
734 QQuickPane::contentItemChange(newItem, oldItem);
737void QQuickScrollView::contentSizeChange(
const QSizeF &newSize,
const QSizeF &oldSize)
739 Q_D(QQuickScrollView);
740 QQuickPane::contentSizeChange(newSize, oldSize);
748 if (d->hasContentWidth || !d->flickableHasExplicitContentWidth) {
749 d->flickable->setContentWidth(newSize.width());
750 d->updateScrollBarWidth();
752 if (d->hasContentHeight || !d->flickableHasExplicitContentHeight) {
753 d->flickable->setContentHeight(newSize.height());
754 d->updateScrollBarHeight();