Advertisement
developer_adaita

SplitViewExample

Sep 7th, 2021 (edited)
1,628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 1.56 KB | None | 0 0
  1. import QtQuick 2.15
  2. import QtQuick.Window 2.15
  3. import QtQuick.Layouts 1.15
  4. import QtQuick.Controls 2.15
  5.  
  6. Window {
  7.     width: 640
  8.     height: 480
  9.     visible: true
  10.     title: qsTr("Hello World")
  11.  
  12.     RowLayout {
  13.         anchors.fill: parent
  14.  
  15.         Rectangle {
  16.             id: sidebar
  17.  
  18.             Layout.preferredWidth: 200
  19.             Layout.fillHeight: true
  20.  
  21.             color: "red"
  22.         }
  23.  
  24.         SplitView {
  25.             id: splitView
  26.             Layout.fillWidth: true
  27.             Layout.fillHeight: true
  28.  
  29.             orientation: Qt.Vertical
  30.  
  31.             property real topSplitterRectHeightRatio: 0.5
  32.             property real bottomSplitterRectHeightRatio: 0.5
  33.  
  34.             Rectangle {
  35.                 id: topSplitterRect
  36.  
  37.                 SplitView.fillWidth: true
  38.                 SplitView.preferredHeight: splitView.availableHeight * splitView.topSplitterRectHeightRatio
  39.  
  40.                 color: "yellow"
  41.             }
  42.  
  43.             Rectangle {
  44.                 id: bottomSplitterRect
  45.  
  46.                 SplitView.fillWidth: true
  47.                 SplitView.preferredHeight: splitView.availableHeight * splitView.bottomSplitterRectHeightRatio
  48.  
  49.                 color: "blue"
  50.             }
  51.  
  52.             onResizingChanged: {
  53.                 if(!resizing) {
  54.                     splitView.topSplitterRectHeightRatio = topSplitterRect.height / splitView.availableHeight
  55.                     splitView.bottomSplitterRectHeightRatio = bottomSplitterRect.height / splitView.availableHeight
  56.                 }
  57.             }
  58.         }
  59.     }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement