首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >网格不支持leftMargin

网格不支持leftMargin
EN

Stack Overflow用户
提问于 2018-06-04 02:27:30
回答 1查看 47关注 0票数 0

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}
        }
    }
}

我做错了什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-04 02:57:43

问题不是网格,而是RadioButton,他们有一个额外的填充:

Control具有以下布局:

因此,解决方案将RadioButtons的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}
        }
    }
}

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50669647

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档