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. Splitview weird behavior
Forum Update on Monday, May 27th 2025

Splitview weird behavior

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
13 Posts 3 Posters 1.1k 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.
  • I Offline
    I Offline
    Imynn
    wrote on last edited by
    #1

    Hello everyone! I am using Qt 5.15.2 and QtQuick.Controls 2. I am having an issue with splitview. When I shrink the window, the right most item goes out of the window bounds, and once I drag the handle, it "jumps" to where it should be. Is there a solution for that?
    STR: drag handle to the right till minimumWidth of the red rectangle is reached, and shrink the window on the right side to the left.

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.Controls 2.15
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
        SplitView {
            anchors.fill: parent
            Rectangle {
                SplitView.preferredWidth: 200
                SplitView.minimumWidth: 200
                color: "blue"
            }
    
            Rectangle {
                color: "red"
                SplitView.minimumWidth: 200
            }
        }
    }
    
    

    Thank you in advance.

    JoeCFDJ 1 Reply Last reply
    0
    • I Imynn

      Hello everyone! I am using Qt 5.15.2 and QtQuick.Controls 2. I am having an issue with splitview. When I shrink the window, the right most item goes out of the window bounds, and once I drag the handle, it "jumps" to where it should be. Is there a solution for that?
      STR: drag handle to the right till minimumWidth of the red rectangle is reached, and shrink the window on the right side to the left.

      import QtQuick 2.15
      import QtQuick.Window 2.15
      import QtQuick.Controls 2.15
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
          SplitView {
              anchors.fill: parent
              Rectangle {
                  SplitView.preferredWidth: 200
                  SplitView.minimumWidth: 200
                  color: "blue"
              }
      
              Rectangle {
                  color: "red"
                  SplitView.minimumWidth: 200
              }
          }
      }
      
      

      Thank you in advance.

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      @Imynn Can you show a picture about your issue? I tested it with qmlscene on Ubuntu 22.04 and did not see any problem.

      I 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        @Imynn Can you show a picture about your issue? I tested it with qmlscene on Ubuntu 22.04 and did not see any problem.

        I Offline
        I Offline
        Imynn
        wrote on last edited by Imynn
        #3

        @JoeCFD Sure. As you can see on the screen, after shrinking the window, red has minimum width, and it is out of window bounds. Once I touch handle, it will shrink the blue rectangle, so the minimum of the red will be within window bounds. SplitView bug.png

        JoeCFDJ I 2 Replies Last reply
        0
        • I Imynn

          @JoeCFD Sure. As you can see on the screen, after shrinking the window, red has minimum width, and it is out of window bounds. Once I touch handle, it will shrink the blue rectangle, so the minimum of the red will be within window bounds. SplitView bug.png

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #4

          @Imynn Check the numbers. I tried the following and the layout seems ok. The width of Red area is squeezed below 200.

              SplitView {
                  anchors.fill: parent
                  Rectangle {
                      SplitView.maximumWidth: 434
                      SplitView.minimumWidth: 434
                      color: "blue"
                  }
          
          JoeCFDJ 1 Reply Last reply
          0
          • JoeCFDJ JoeCFD

            @Imynn Check the numbers. I tried the following and the layout seems ok. The width of Red area is squeezed below 200.

                SplitView {
                    anchors.fill: parent
                    Rectangle {
                        SplitView.maximumWidth: 434
                        SplitView.minimumWidth: 434
                        color: "blue"
                    }
            
            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by
            #5

            @JoeCFD With your code, I can not move the blue area to width 434. the splitter stops at where red area has width 200.

            import QtQuick.Window 2.15
            import QtQuick.Controls 2.15
            Window {
               width: 474
               height: 480
               visible: true
               title: qsTr("Hello World")
               SplitView {
                   anchors.fill: parent
                   Rectangle {
                       SplitView.preferredWidth: 200
                       SplitView.minimumWidth: 200
                       color: "blue"
                   }
                   Rectangle {
                       color: "red"
                       SplitView.minimumWidth: 200
                   }
               }
            }
            
            I 1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              @JoeCFD With your code, I can not move the blue area to width 434. the splitter stops at where red area has width 200.

              import QtQuick.Window 2.15
              import QtQuick.Controls 2.15
              Window {
                 width: 474
                 height: 480
                 visible: true
                 title: qsTr("Hello World")
                 SplitView {
                     anchors.fill: parent
                     Rectangle {
                         SplitView.preferredWidth: 200
                         SplitView.minimumWidth: 200
                         color: "blue"
                     }
                     Rectangle {
                         color: "red"
                         SplitView.minimumWidth: 200
                     }
                 }
              }
              
              I Offline
              I Offline
              Imynn
              wrote on last edited by
              #6

              @JoeCFD Yes, once it stops, shrink the window. And handle won't move and splitview children won't resize. So window size gets smaller, and splitview children don't change their width, which causes blue rectangle to be out of window bounds

              1 Reply Last reply
              0
              • I Imynn

                @JoeCFD Sure. As you can see on the screen, after shrinking the window, red has minimum width, and it is out of window bounds. Once I touch handle, it will shrink the blue rectangle, so the minimum of the red will be within window bounds. SplitView bug.png

                I Offline
                I Offline
                Imynn
                wrote on last edited by
                #7

                @Imynn this is after shrinking the window. Initially the window was 640x480

                JoeCFDJ 1 Reply Last reply
                0
                • I Imynn

                  @Imynn this is after shrinking the window. Initially the window was 640x480

                  JoeCFDJ Offline
                  JoeCFDJ Offline
                  JoeCFD
                  wrote on last edited by
                  #8

                  @Imynn I tried it on Linux. After splitter stops, red area will disappear when I reduce the width of the window. No problem at all on Linux.

                  I 1 Reply Last reply
                  0
                  • JoeCFDJ JoeCFD

                    @Imynn I tried it on Linux. After splitter stops, red area will disappear when I reduce the width of the window. No problem at all on Linux.

                    I Offline
                    I Offline
                    Imynn
                    wrote on last edited by
                    #9

                    @JoeCFD Yes, red area disappears, because it's out of window bounds. It still has width 200 which is minimumWidth. The behavior that I expect is that it doesn't disappear, but instead moves to the left and blue rectangle shrinks. Is it achievable?

                    JoeCFDJ 1 Reply Last reply
                    0
                    • I Imynn

                      @JoeCFD Yes, red area disappears, because it's out of window bounds. It still has width 200 which is minimumWidth. The behavior that I expect is that it doesn't disappear, but instead moves to the left and blue rectangle shrinks. Is it achievable?

                      JoeCFDJ Offline
                      JoeCFDJ Offline
                      JoeCFD
                      wrote on last edited by JoeCFD
                      #10

                      @Imynn remove
                      SplitView.minimumWidth: 200
                      from the first Rectangle(blue one).

                      I 1 Reply Last reply
                      0
                      • JoeCFDJ JoeCFD

                        @Imynn remove
                        SplitView.minimumWidth: 200
                        from the first Rectangle(blue one).

                        I Offline
                        I Offline
                        Imynn
                        wrote on last edited by Imynn
                        #11

                        @JoeCFD It didn't help either.

                        import QtQuick 2.15
                        import QtQuick.Window 2.15
                        import QtQuick.Controls 2.15
                        Window {
                            id: root
                            width: 640
                            height: 480
                            visible: true
                            title: qsTr("Hello World")
                            SplitView {
                                anchors.fill: parent
                                Rectangle {
                                    id: rectBlue
                                    SplitView.preferredWidth: 400
                                    color: "blue"
                                    Column {
                                        anchors.centerIn: parent
                                        Text {
                                            color: "white"
                                            text: "Red width %1".arg(rect.width)
                                        }
                                        Text {
                                            color: "white"
                                            text: "Window width %1".arg(root.width)
                                        }
                                        Text {
                                            color: "white"
                                            text: "Blue width %1".arg(rectBlue.width)
                                        }
                                    }
                                }
                        
                                Rectangle {
                                    id: rect
                                    color: "red"
                                    SplitView.minimumWidth: 200
                                }
                            }
                        }
                        
                        

                        With above code when I resize window (make it smaller) both Rectangles go out of the window bounds
                        5cb52c4d-8d33-42b9-9a3f-0a5e764bdc23-image.png
                        eba6f2f7-d717-4595-aa28-c87c46c1c181-image.png
                        These images are taken when inspecting the scene with gammaray. On the first screen you can see actual size of the blue rectangle, which is out of window bounds. On the second screen you can see size and position of the red rectangle which is out of window bounds as well. And text informations provides actual width of all components. What I expect after resizing the window according to the code I provided above: 200(minimumWidth) red width, 90 blue width, 6 handle, which in sum wiil give window width 296.

                        JoeCFDJ 1 Reply Last reply
                        0
                        • I Imynn

                          @JoeCFD It didn't help either.

                          import QtQuick 2.15
                          import QtQuick.Window 2.15
                          import QtQuick.Controls 2.15
                          Window {
                              id: root
                              width: 640
                              height: 480
                              visible: true
                              title: qsTr("Hello World")
                              SplitView {
                                  anchors.fill: parent
                                  Rectangle {
                                      id: rectBlue
                                      SplitView.preferredWidth: 400
                                      color: "blue"
                                      Column {
                                          anchors.centerIn: parent
                                          Text {
                                              color: "white"
                                              text: "Red width %1".arg(rect.width)
                                          }
                                          Text {
                                              color: "white"
                                              text: "Window width %1".arg(root.width)
                                          }
                                          Text {
                                              color: "white"
                                              text: "Blue width %1".arg(rectBlue.width)
                                          }
                                      }
                                  }
                          
                                  Rectangle {
                                      id: rect
                                      color: "red"
                                      SplitView.minimumWidth: 200
                                  }
                              }
                          }
                          
                          

                          With above code when I resize window (make it smaller) both Rectangles go out of the window bounds
                          5cb52c4d-8d33-42b9-9a3f-0a5e764bdc23-image.png
                          eba6f2f7-d717-4595-aa28-c87c46c1c181-image.png
                          These images are taken when inspecting the scene with gammaray. On the first screen you can see actual size of the blue rectangle, which is out of window bounds. On the second screen you can see size and position of the red rectangle which is out of window bounds as well. And text informations provides actual width of all components. What I expect after resizing the window according to the code I provided above: 200(minimumWidth) red width, 90 blue width, 6 handle, which in sum wiil give window width 296.

                          JoeCFDJ Offline
                          JoeCFDJ Offline
                          JoeCFD
                          wrote on last edited by
                          #12

                          @Imynn said in Splitview weird behavior:

                          SplitView

                          https://doc.qt.io/qt-5/qml-qtquick-controls2-splitview.html

                          1 Reply Last reply
                          0
                          • B Offline
                            B Offline
                            burnack
                            wrote on last edited by
                            #13

                            Hi @Imynn , I just faced the same problem and was able to solve it the following way.
                            The problem is that from the documentation there is always 1 element in a SplitView that fills the width (height for vertical). And by default it is the last one. By regulating that element depending on the window width you can choose which one changes width along with the window. So I set red.fillWidth to false and blue.fillWidth to true when the window width is less than the threshold.
                            I even did smth like

                            splitview.onResizingChanged: if (!resizing) userBlueWidth = blue.width; // saving the blue width on the splitter drag release
                            fillerRectIndex: Window.width < userBlueWidth + splitter.width + red.minWidth ? blueIndex : redIndex
                            Red {
                            SplitView.fillWidth: fillRectIndex == redIndex
                            }
                            Blue {
                            SplitView.fillWidth: fillRectIndex == blueIndex
                            }

                            Then the blue becomes the filler and starts shrinking.
                            Good luck!

                            1 Reply Last reply
                            1

                            • Login

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