Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Confusing ScrollView in Qt.Quick.Controls2
Forum Updated to NodeBB v4.3 + New Features

Confusing ScrollView in Qt.Quick.Controls2

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 521 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fromis_9
    wrote on last edited by fromis_9
    #1
    // Qt 5.15.2
    import QtQuick 2.15
    import QtQuick.Controls 2.15
    
    ScrollView { id: scrollView
      function scrollToY(y) {
        scrollView.contentItem.contentY = y
        scrollView.contentItem.returnToBounds() // this works
      }
      contentItem.boundsBehavior: Flickable.StopAtBounds 
      // Cannot assign to non-existent property "boundsBehavior"
     
      Pane {
      // ...
      // my contents is in this Pane
      // ...
      }
    }
    

    Above code is where I lost.
    In ScrollView QML Type docs, there is NO description that what type the contentItem is. List of All Members for ScrollView docs said contentItem is the member inherited from Control, and the type is Item. But my contentItem above code has returnToBounds() method and it works!!
    So I assumed that the contentItem's type is maybe Flickable, cause the only type which has returnToBounds() is Flickable, and expect that it also has boundsBehavior property. But it doesnt.
    I'm soooo confused. Why the document has no full description about contentItem in ScrollView? What the heck is real contentItem?

    GrecKoG 1 Reply Last reply
    0
    • F fromis_9
      // Qt 5.15.2
      import QtQuick 2.15
      import QtQuick.Controls 2.15
      
      ScrollView { id: scrollView
        function scrollToY(y) {
          scrollView.contentItem.contentY = y
          scrollView.contentItem.returnToBounds() // this works
        }
        contentItem.boundsBehavior: Flickable.StopAtBounds 
        // Cannot assign to non-existent property "boundsBehavior"
       
        Pane {
        // ...
        // my contents is in this Pane
        // ...
        }
      }
      

      Above code is where I lost.
      In ScrollView QML Type docs, there is NO description that what type the contentItem is. List of All Members for ScrollView docs said contentItem is the member inherited from Control, and the type is Item. But my contentItem above code has returnToBounds() method and it works!!
      So I assumed that the contentItem's type is maybe Flickable, cause the only type which has returnToBounds() is Flickable, and expect that it also has boundsBehavior property. But it doesnt.
      I'm soooo confused. Why the document has no full description about contentItem in ScrollView? What the heck is real contentItem?

      GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      As far as the QML engine knows, it's an Item. That's why you can't do contentItem.boundsBehavior: Flickable.StopAtBounds. Left-hand expressions have to fully typed and can't dynamically adapt. Right-hand expressions or Javascript expressions can, that's why you can call returnToBounds() in your function.

      contentItem is in fact a Flickable but you can use this fact for a declarative binding on it.
      Most background are Rectangle but they are declared as Item and since you could change it to be a simple Item or any of its subclasses you can't do background.radius: 8 but you can do background.visible: false because visible is a property from Item.

      In you case you could set the boundsBehaviour in a Component.onCompleted handler or with a Binding:

      Binding {
          target: scrollView.contentItem
          property: "boundsBehaviour"
          value: Flickable.StopAtBounds
      }
      
      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved