Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-117687

Custom template ScrollBar has no effect on ScrollView content position when not declared as inline or external component

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.12.8, 5.15.2, 5.15.3
    • Quick: Controls 2
    • None
    • Linux/X11

    Description

      In the enclosed sample:

      • The top ScrollView is working fine
      • With the second, where the code is inline, the program will crash without this commit when pressing the Scrollbar (see stack trace below). With the fix, the scrollbar is still unusable (dragging on the scrollbar doesn't change the view's position).
         

        #0  0x00007f1aae43bc30 in QQuickItem::width() const ()
           from /home/pierre/Qt/5.15.2/gcc_64/bin/../lib/libQt5Quick.so.5
        #1  0x00007f1a782d2785 in QQuickScrollBarAttachedPrivate::scrollHorizontal() ()
           from /home/pierre/Qt/5.15.2/gcc_64/qml/QtQuick/Controls.2/../../../lib/libQt5QuickTemplates2.so.5
        #2  0x00007f1aab8d5f30 in void doActivate<false>(QObject*, int, void**) ()
           from /home/pierre/Qt/5.15.2/gcc_64/bin/../lib/libQt5Core.so.5
        #3  0x00007f1a782d2a64 in QQuickScrollBar::setPosition(double) ()
           from /home/pierre/Qt/5.15.2/gcc_64/qml/QtQuick/Controls.2/../../../lib/libQt5QuickTemplates2.so.5
        #4  0x00007f1a782a36d5 in QQuickControl::mouseMoveEvent(QMouseEvent*) ()
           from /home/pierre/Qt/5.15.2/gcc_64/qml/QtQuick/Controls.2/../../../lib/libQt5QuickTemplates2.so.5
        #5  0x00007f1aae449f5e in QQuickItem::event(QEvent*) ()
           from /home/pierre/Qt/5.15.2/gcc_64/bin/../lib/libQt5Quick.so.5

        [...]

      import QtQuick 2.12
      import QtQuick.Window 2.12
      import QtQuick.Controls 2.12
      import QtQuick.Templates 2.12 as T
      
      Window {
          width: 300
          height: 400
          visible: true
          title: qsTr("Example")
      
          component MyScrollView: T.ScrollView {
              id: control
      
              implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
                                      contentWidth + leftPadding + rightPadding)
              implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
                                       contentHeight + topPadding + bottomPadding)
      
      
              ScrollBar.horizontal: ScrollBar {
                  parent: control
                  x: control.leftPadding
                  y: control.height - height
                  width: control.availableWidth
              }
          }
      
          MyScrollView {
              id: view1
      
              height: 200
      
              anchors {
                  top: parent.top
                  left: parent.left
                  right: parent.right
              }
      
              contentWidth: r1.width
              contentHeight: r1.height
      
              Rectangle {
                  id: r1
                  width: 500
                  height: 200
                  gradient: Gradient {
                      orientation: Gradient.Horizontal
                      GradientStop { position: 0.0; color: "red" }
                      GradientStop { position: 1.0; color: "green" }
                  }
              }
          }
      
          T.ScrollView {
              id: view2
      
              height: 200
      
              anchors {
                  top: view1.bottom
                  left: parent.left
                  right: parent.right
              }
      
              implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
                                      contentWidth + leftPadding + rightPadding)
              implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
                                       contentHeight + topPadding + bottomPadding)
      
              contentWidth: r2.width
              contentHeight: r2.height
      
              ScrollBar.horizontal: ScrollBar {
                  parent: view2
                  x: view2.leftPadding
                  y: view2.height - height
                  width: view2.availableWidth
              }
      
              Rectangle {
                  id: r2
                  width: 500
                  height: 200
                  gradient: Gradient {
                      orientation: Gradient.Horizontal
                      GradientStop { position: 0.0; color: "blue" }
                      GradientStop { position: 1.0; color: "yellow" }
                  }
              }
          }
      }
      

      Attachments

        1. Peek 2023-10-03 09-29.mp4
          313 kB
          Pierre Lamot
        2. sample.tar.bz2
          0.8 kB
          Pierre Lamot
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            chub Pierre Lamot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes