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}
}
}
}
我做错了什么吗?
发布于 2018-06-04 02:57:43
问题不是网格,而是RadioButton
,他们有一个额外的填充:
Control具有以下布局:
因此,解决方案将RadioButton
s的leftPadding
设置为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}
}
}
}
https://stackoverflow.com/questions/50669647
复制相似问题