У меня есть следующие пользовательские QML Item
, который будет представлять собой пин-код начального графического элемента:Предметы, которые не правильно распределены по GridLayout
import QtQuick 2.0
import QtQuick.Layouts 1.2
import QtQuick.Controls 1.3
import "../items"
Item
{
id: ueKeypad
width: 512
height: 512
Rectangle
{
id: ueKeypadWrapper
antialiasing: true
anchors.fill: parent
ColumnLayout
{
id: ueKeypadLayoutMain
antialiasing: true
layoutDirection: Qt.LeftToRight
spacing: 8
anchors.fill: parent
ColumnLayout
{
id: ueKeypadTitleLayout
layoutDirection: Qt.LeftToRight
Layout.fillWidth: true
Layout.minimumHeight: 24
Layout.preferredHeight: 24
Layout.maximumHeight: 24
Text
{
Layout.fillWidth: true
Layout.fillHeight: true
text: qsTr("PIN ENTRY")
clip: true
font.bold: true
font.pointSize: 24
textFormat: Text.RichText
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
} // Text
} // ColumnLayout
GridLayout
{
id: ueKeypadNumbersLayout
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
layoutDirection: Qt.LeftToRight
columnSpacing: 8
rowSpacing: 8
flow: GridLayout.LeftToRight
columns: 3
UeButton
{
id: ueKeypadButton1
Layout.minimumHeight: 32
Layout.preferredHeight: 32
Layout.maximumHeight: 32
ueText: qsTr("1")
}
UeButton
{
id: ueKeypadButton2
Layout.minimumHeight: 32
Layout.preferredHeight: 32
Layout.maximumHeight: 32
ueText: qsTr("2")
}
UeButton
{
id: ueKeypadButton3
Layout.minimumHeight: 32
Layout.preferredHeight: 32
Layout.maximumHeight: 32
ueText: qsTr("3")
}
UeButton
{
id: ueKeypadButton4
Layout.minimumHeight: 32
Layout.preferredHeight: 32
Layout.maximumHeight: 32
ueText: qsTr("4")
}
UeButton
{
id: ueKeypadButton5
Layout.minimumHeight: 32
Layout.preferredHeight: 32
Layout.maximumHeight: 32
ueText: qsTr("5")
}
UeButton
{
id: ueKeypadButton6
Layout.minimumHeight: 32
Layout.preferredHeight: 32
Layout.maximumHeight: 32
ueText: qsTr("6")
}
UeButton
{
id: ueKeypadButton7
Layout.minimumHeight: 32
Layout.preferredHeight: 32
Layout.maximumHeight: 32
ueText: qsTr("7")
}
UeButton
{
id: ueKeypadButton8
Layout.minimumHeight: 32
Layout.preferredHeight: 32
Layout.maximumHeight: 32
ueText: qsTr("8")
}
UeButton
{
id: ueKeypadButton9
Layout.minimumHeight: 32
Layout.preferredHeight: 32
Layout.maximumHeight: 32
ueText: qsTr("9")
}
} // GridLayout
RowLayout
{
id: ueKeypadActionLayout
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
layoutDirection: Qt.LeftToRight
spacing: 8
UeButton
{
id: ueKeypadButtonOk
ueText: qsTr("Ok")
} // UeButton
UeButton
{
id: ueKeypadButton0
ueText: qsTr("0")
Layout.minimumHeight: 32
Layout.preferredHeight: 32
Layout.maximumHeight: 32
} // UeButton
UeButton
{
id: ueKeypadButtonCancel
ueText: qsTr("Cancel")
} // UeButton
} // RowLayout
} // ColumnLayout
} // Rectangle
} // Item
Он использует пользовательский QML Button
, названный UeButton
:
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick 2.5
Button
{
property string ueText
id: ueButton
text: ueText
style: ButtonStyle
{
background: Rectangle
{
antialiasing: true
smooth: true
gradient: Gradient
{
GradientStop
{
position: 0
color: "#ffffff"
} // GradientStop
GradientStop
{
position: 0.418
color: "#000000"
} // GradientStop
} // Gradient
border.color: "steelblue"
border.width: control.activeFocus?2:1
radius: 4
} // background
label: Text
{
color: "#ffffff"
font.bold: true
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pointSize: 16
text: control.text
} // label
} // ButtonStyle
} // ueButton
Если я просматриваю первый код в Инструменте конструктора QtCreator, я получаю следующую ситуацию:
Почему Button
не распространяется на GridLayout
? То же самое относится к нижнему RowLayout
, чьи Item
s (три Item
с типа UeButton
) не центрированы и выровнены по всему RowLayout
?