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. Resizing controls in SplitView
Forum Updated to NodeBB v4.3 + New Features

Resizing controls in SplitView

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 120 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.
  • T Offline
    T Offline
    TheEnigmist
    wrote last edited by
    #1

    Hello, I'm new to QML and Quick, and I'm trying them out with Qt 6.10.
    I have some questions about SplitView: the controls inside one of the split views go over the rectangles instead of resizing or "overflowing".
    This is my sample code:

    ApplicationWindow {
        id: mainWindow
        visible: true
           
        color: "green"
        ColumnLayout {
            anchors.fill: parent
            anchors.margins: 10
            spacing: 10
            SplitView {
                id: splitView
                Layout.fillWidth: true; Layout.fillHeight: true
                orientation: Qt.Horizontal
    
                Rectangle {
                    id: leftPane
                    color: "blue"
    
                    ColumnLayout {
                        anchors.centerIn: parent
    
                        RadioButton { text: qsTr("Small") }
                        RadioButton { text: Window.active ? "active" : "inactive";  checked: true;}
                        RadioButton { text: qsTr("Large");}
    
        
                        Button { text: qsTr("Button") }
                        RoundButton  { text: qsTr("Button"); radius: 10}
    
            
                        Switch { text: qsTr("First"); checked: true }
                        Switch { text: qsTr("Second"); checked: true; enabled: false }
                        Switch { text: qsTr("Third")}
    
                        ComboBox {
                            model: ["First", "Second", "Third"]
                        }
    
                        Slider {
                            from: 1
                            value: 25
                            to: 100
                        }
                        TextField {
                            placeholderText: qsTr("Enter name")
                        }
    
                        SpinBox {
                            value: 50
                        }
                    }
                }
                Rectangle {
                    id: rightPane
                    color: "red"
                    SplitView.fillWidth: true
    
                    Column {
                        anchors.centerIn: parent
    
                        RadioButton { text: qsTr("Small") }
                        RadioButton { text: Window.active ? "active" : "inactive";  checked: true;}
                        RadioButton { text: qsTr("Large");}
                    }
                }
            }
    
            RowLayout {
                    spacing: 10
                
                    Label { text: qsTr("Footer Text"); color: "white" }
                    Button { text: qsTr("Action"); Layout.fillWidth: true }
                }
        }
    }
    

    This is what I get
    7fb5cc70-d85a-4c10-b910-49bd39bb815f-image.png

    I was expecting the control to resize itself to match the size of the blue rectangle, or to overflow on the right while staying inside the rectangle.
    What am I missing?

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      zvoopz
      wrote last edited by zvoopz
      #2

      If you want controls stay inside blue rectangle anchor layout

      Rectangle {
                      id: leftPane
                      color: "blue"
      
                      ColumnLayout {
                          //anchors.centerIn: parent
                          anchors.left:parent.left
                          anchors.verticalCenter: parent.verticalCenter
      //also you can put some margin if you need to
                          anchors.leftMargin: parent.width/20
      

      9a02b85f-a2bb-45a1-8867-2621fc84ea66-зображення.png

      T 1 Reply Last reply
      0
      • Z zvoopz

        If you want controls stay inside blue rectangle anchor layout

        Rectangle {
                        id: leftPane
                        color: "blue"
        
                        ColumnLayout {
                            //anchors.centerIn: parent
                            anchors.left:parent.left
                            anchors.verticalCenter: parent.verticalCenter
        //also you can put some margin if you need to
                            anchors.leftMargin: parent.width/20
        

        9a02b85f-a2bb-45a1-8867-2621fc84ea66-зображення.png

        T Offline
        T Offline
        TheEnigmist
        wrote last edited by
        #3

        @zvoopz said in Resizing controls in SplitView:

        If you want controls stay inside blue rectangle anchor layout

        Rectangle {
                        id: leftPane
                        color: "blue"
        
                        ColumnLayout {
                            //anchors.centerIn: parent
                            anchors.left:parent.left
                            anchors.verticalCenter: parent.verticalCenter
        //also you can put some margin if you need to
                            anchors.leftMargin: parent.width/20
        

        9a02b85f-a2bb-45a1-8867-2621fc84ea66-зображення.png

        Oh thanks, it worked!
        I've another question.
        I added these lines too:

        anchors.right: parent.right
        anchors.rightMargin: 10
        

        I found out that, in order to create an 'empty' space defined by the right margin, I need to add Layout.fillWidth: true to all controls with a width greater than SplitView.minimumWidth.
        Is there a better way than adding Layout.fillWidth: true to all elements?

        Z 1 Reply Last reply
        0
        • T TheEnigmist

          @zvoopz said in Resizing controls in SplitView:

          If you want controls stay inside blue rectangle anchor layout

          Rectangle {
                          id: leftPane
                          color: "blue"
          
                          ColumnLayout {
                              //anchors.centerIn: parent
                              anchors.left:parent.left
                              anchors.verticalCenter: parent.verticalCenter
          //also you can put some margin if you need to
                              anchors.leftMargin: parent.width/20
          

          9a02b85f-a2bb-45a1-8867-2621fc84ea66-зображення.png

          Oh thanks, it worked!
          I've another question.
          I added these lines too:

          anchors.right: parent.right
          anchors.rightMargin: 10
          

          I found out that, in order to create an 'empty' space defined by the right margin, I need to add Layout.fillWidth: true to all controls with a width greater than SplitView.minimumWidth.
          Is there a better way than adding Layout.fillWidth: true to all elements?

          Z Offline
          Z Offline
          zvoopz
          wrote last edited by
          #4

          @TheEnigmist said in Resizing controls in SplitView:

          I added these lines too:

          What is your goal? You can anchor either to left or to right, not both

          1 Reply Last reply
          0
          • GrecKoG Offline
            GrecKoG Offline
            GrecKo
            Qt Champions 2018
            wrote last edited by
            #5

            You can anchor to both left and right. anchoring the column layout to the parent rectangle and using Layout.fillWidth: true for its children is the correct way to go here.

            I don't really understand the part about the SplitView.minimumWidth here.

            T 1 Reply Last reply
            0
            • T TheEnigmist has marked this topic as solved
            • GrecKoG GrecKo

              You can anchor to both left and right. anchoring the column layout to the parent rectangle and using Layout.fillWidth: true for its children is the correct way to go here.

              I don't really understand the part about the SplitView.minimumWidth here.

              T Offline
              T Offline
              TheEnigmist
              wrote last edited by TheEnigmist
              #6

              Yes, @GrecKo is right about the anchor, and the information about the SplitView.minimumWidth is misleading. Sorry about that.

              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