1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
// This example was created for the blog post about responsive layouts:
// https://www.qt.io/blog/responsive-layouts-in-qt
import QtQuick
import QtQuick.Layouts
import QtQuick.Window
import QtQuick.Controls
Window {
id: window
width: 600
height: 800
minimumHeight: 500
minimumWidth: 160
title: "Window: (" + width + "x" + height + ")"
visible: true
component MyButton : Rectangle {
implicitWidth: 56
implicitHeight: 56
Layout.minimumWidth: 56
Layout.minimumHeight: 56
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignHCenter
property string label: ""
color: "#eaeaea"
Rectangle {
implicitWidth: 56
implicitHeight: 56
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
color: "#eaeaea"
Text {
font.pixelSize: 32
font.bold: true
anchors.centerIn: parent
text: label
color: "#243a5e"
}
}
}
LayoutChooser {
id: layoutChooser
width: parent.width
height: parent.height
layoutChoices: [
smallLayout,
largeLayout
]
criteria: [
window.width < rl2.Layout.minimumWidth + rl2.anchors.margins * 2,
true
]
MyButton { id: aButton; label: "A"; z: 2 }
MyButton { id: bButton; label: "B"; z: 2 }
MyButton { id: cButton; label: "C"; z: 2 }
MyButton { id: dButton; label: "D"; z: 2 }
MyButton { id: eButton; label: "E"; z: 2 }
MyButton { id: fButton; label: "F"; z: 2 }
MyButton { id: gButton; label: "G"; z: 2 }
Rectangle {
id: rect
Layout.fillWidth: true
Layout.fillHeight: true
color: "#fff"
}
property Item smallLayout: RowLayout {
parent: layoutChooser
height: parent.height
width: parent.width
spacing: 0
Rectangle {
id: buttonRect1
width: 200
Layout.fillHeight: true
color: "#c8c8c8"
ColumnLayout {
anchors.margins: 10
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
spacing: 8
LayoutItemProxy { target: aButton }
LayoutItemProxy { target: bButton }
LayoutItemProxy { target: cButton }
LayoutItemProxy { target: dButton }
LayoutItemProxy { target: eButton }
LayoutItemProxy { target: fButton }
LayoutItemProxy { target: gButton }
}
}
LayoutItemProxy { target: rect }
}
property Item largeLayout: ColumnLayout {
parent: layoutChooser
height: parent.height
width: parent.width
spacing: 0
Rectangle {
id: buttonRect2
Layout.fillWidth: true
height: rl2.height + rl2.anchors.margins * 2
implicitWidth: rl2.width + rl2.anchors.margins * 2
color: "#c8c8c8"
RowLayout {
id: rl2
anchors.margins: 10
anchors.top: parent.top
anchors.left: parent.left
spacing: 8
LayoutItemProxy { target: aButton }
LayoutItemProxy { target: bButton }
LayoutItemProxy { target: cButton }
LayoutItemProxy { target: dButton }
LayoutItemProxy { target: eButton }
LayoutItemProxy { target: fButton }
LayoutItemProxy { target: gButton }
}
}
LayoutItemProxy { target: rect }
}
}
}
|