网格不尊重 leftMargin
Grid does not respect leftMargin
Qt 5.11。我使用 Column
来定位我的控件。对于此列元素,我设置了 anchors.leftMargin: 10
。除 Grid
.
外,所有子项都遵守此规定
我得到的截图:
QML代码:
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Column
{
anchors.fill: parent
anchors.leftMargin: 10
RadioButton
{
text: qsTr("System proxy")
}
RadioButton
{
text: qsTr("No proxy")
}
RadioButton
{
text: qsTr("Configure manually:")
}
Grid
{
columns: 5
spacing: 10
Label {text: " "}
Label {text: qsTr("Address")}
Label {text: qsTr("Port")}
Label {text: qsTr("Login")}
Label {text: qsTr("Password")}
Label {text: "HTTP"}
TextField {width: 100}
TextField {width: 40}
TextField {width: 100}
TextField {width: 100}
}
}
}
我是不是做错了什么?
问题不在于网格,而是 RadioButton
,它们有一个额外的填充:
A Control 具有以下布局:
所以解决方案将 leftPadding
设置为 RadioButton
的 0:
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Column
{
anchors.fill: parent
anchors.leftMargin: 10
RadioButton
{
text: qsTr("System proxy")
leftPadding: 0
}
RadioButton
{
text: qsTr("No proxy")
leftPadding: 0
}
RadioButton
{
text: qsTr("Configure manually:")
leftPadding: 0
}
Grid
{
columns: 5
spacing: 10
Label {text: " "}
Label {text: qsTr("Address")}
Label {text: qsTr("Port")}
Label {text: qsTr("Login")}
Label {text: qsTr("Password")}
Label {text: "HTTP"}
TextField {width: 100}
TextField {width: 40}
TextField {width: 100}
TextField {width: 100}
}
}
}
Qt 5.11。我使用 Column
来定位我的控件。对于此列元素,我设置了 anchors.leftMargin: 10
。除 Grid
.
我得到的截图:
QML代码:
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Column
{
anchors.fill: parent
anchors.leftMargin: 10
RadioButton
{
text: qsTr("System proxy")
}
RadioButton
{
text: qsTr("No proxy")
}
RadioButton
{
text: qsTr("Configure manually:")
}
Grid
{
columns: 5
spacing: 10
Label {text: " "}
Label {text: qsTr("Address")}
Label {text: qsTr("Port")}
Label {text: qsTr("Login")}
Label {text: qsTr("Password")}
Label {text: "HTTP"}
TextField {width: 100}
TextField {width: 40}
TextField {width: 100}
TextField {width: 100}
}
}
}
我是不是做错了什么?
问题不在于网格,而是 RadioButton
,它们有一个额外的填充:
A Control 具有以下布局:
所以解决方案将 leftPadding
设置为 RadioButton
的 0:
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Column
{
anchors.fill: parent
anchors.leftMargin: 10
RadioButton
{
text: qsTr("System proxy")
leftPadding: 0
}
RadioButton
{
text: qsTr("No proxy")
leftPadding: 0
}
RadioButton
{
text: qsTr("Configure manually:")
leftPadding: 0
}
Grid
{
columns: 5
spacing: 10
Label {text: " "}
Label {text: qsTr("Address")}
Label {text: qsTr("Port")}
Label {text: qsTr("Login")}
Label {text: qsTr("Password")}
Label {text: "HTTP"}
TextField {width: 100}
TextField {width: 40}
TextField {width: 100}
TextField {width: 100}
}
}
}