Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Redirect component to another container



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

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

    My problem is if I use this component as follows:

    SidePanel{
         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".

    https://doc.qt.io/qt-5/qtqml-syntax-objectattributes.html#default-properties



  • This actually works! Thank you very much!


Log in to reply