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. Dealing with dynamic content in ScrollView
Forum Updated to NodeBB v4.3 + New Features

Dealing with dynamic content in ScrollView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 548 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.
  • P Offline
    P Offline
    PavloPonomarov
    wrote on last edited by
    #1

    Hello!
    To describe my question I have created a following example:

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.Layouts 1.12
    import QtQuick.Controls 2.12
    
    Window {
        width: 640
        height: 480
        visible: true
    
        ScrollView{
            id: container
            anchors.fill: parent
            contentWidth: width*2
            contentHeight: height*2
            property int dynamicElementCount: 0
            function sayHello(){
                console.log("Child element asked the container to say hello");
            }
            Button{
                text:"Create dynamic"
                onClicked: {
                    Qt.createQmlObject("
                        import QtQuick 2.15;
                        import QtQuick.Controls 2.12;
                        Button{
                            x: 100*container.dynamicElementCount;
                            text:\"Dynamic"+container.dynamicElementCount+"\";
                            onClicked:{ container.sayHello() }}
                    ", container.contentItem.contentItem, "Button"+container.dynamicElementCount);
                    container.dynamicElementCount++;
                }
            }
        }
    }
    

    I want to create dynamic element as ScrollView content, so it would be scrollable. As I've noticed, to scroll dynamic content its parent should be not the ScrollView itself but the QQuickItem that is 3rd element in ScrollView hierarchy: ScrollView contentItem is Flickable, and its contentItem is QQuickItem.
    So practically to create a dynamic element inside ScrollView I have to create it inside ScrollView.contentItem.contentItem. And if I want to address to ScrollView properties from the inside of dynamic object I could either use id or relative path will be parent.parent.propertyName.
    Is there a better way to do that?

    1 Reply Last reply
    0
    • GabrielRRG Offline
      GabrielRRG Offline
      GabrielRR
      wrote on last edited by
      #2

      Hello, you can always set a property in the parent object and bind it directly like:

      property1 = parent.propertyName

      property2 = child.propertyName

      Lic-Ing. Jose Gabriel Lopez Villalobos
      Embedded Software Engineer
      RidgeRun Engineering Ltd.
      www.ridgerun.com
      Email: gabriel.lopez@ridgerun.com

      1 Reply Last reply
      0

      • Login

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