Qt World Summit: Register Today!

Redirect component to another container

  • Hello. I'm currently writing a retractable side panel. Example code:

    	property var parentElement: parent
            width: parentElement.width
            height: parentElement.height
            property var side: "left"
    		x: 0
                    y: 0
                    width: 20
                    height: parentElement.height
                    flat: true
                    text: (side === "left")?">":"<"
    		onClicked: { /*insert logic here*/);
                 id: content

    My problem is if I use this component as follows:

         Text{ text: "Some content" }
          Button { text: "Do stuff"; onClick: { /*do suff*/ }}

    then components will be added to RowLayout.
    Is there a way to place content directly to the Pane?

  • Moderators

    Not sure but you might get this to work using default property:

    RowLayout {
      default property alias items: content.children
      Button {}
      Pane {
        id: content

    Sorry I can't test it at the moment, not sure if this code will work. There are also a few more ways to do it, but more "hacky".


  • This actually works! Thank you very much!

Log in to reply