在这个QML样本中,利润来自哪里?
我已经看了很多关于QML中内容边距的问题,但是所有的答案都指向缺少在这个QML样本中,利润来自哪里?,qml,qtquick2,qtquickcontrols2,Qml,Qtquick2,Qtquickcontrols2,我已经看了很多关于QML中内容边距的问题,但是所有的答案都指向缺少间距:0属性。我已经做了所有这些,但仍然有我无法消除的奇怪空间。有人能解释为什么这个QML代码: import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Test")
间距:0
属性。我已经做了所有这些,但仍然有我无法消除的奇怪空间。有人能解释为什么这个QML代码:
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Test")
RowLayout {
spacing: 0
anchors.margins: 0, 0, 0, 0
anchors.fill: parent;
Pane {
anchors.margins: 0, 0, 0, 0
id: menuPane
anchors.top: parent.top;
anchors.bottom: parent.bottom;
width: 200
ColumnLayout {
spacing: 0
anchors.fill: parent
anchors.margins: 0, 0, 0, 0
Rectangle {
id: testRect
Layout.fillWidth: true
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
height: 20
color: "green"
}
}
}
Pane {
anchors.margins: 0, 0, 0, 0
anchors.left: menuPane.right
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
Rectangle {
anchors.margins: 0, 0, 0, 0
anchors.fill: parent
color: "black"
}
}
}
}
是这样渲染的吗?为什么矩形之间有边距?
这个答案很简短:
将窗格的属性padding
设置为0,这样就不会剩下任何边距了。您还可以单独设置所有填充(leftPadding…),这些属性从中继承 在您的示例中如下所示:
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Test")
RowLayout {
spacing: 0
anchors.margins: 0
anchors.fill: parent;
Pane {
anchors.margins: 0
id: menuPane
anchors.top: parent.top;
anchors.bottom: parent.bottom;
width: 200
padding: 0
ColumnLayout {
spacing: 0
anchors.fill: parent
anchors.margins: 0
Rectangle {
id: testRect
Layout.fillWidth: true
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
height: 20
color: "green"
}
}
Component.onCompleted: console.log(bottomPadding, leftPadding)
}
Pane {
anchors.margins: 0
anchors.left: menuPane.right
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
padding: 0
Rectangle {
anchors.margins: 0
anchors.fill: parent
color: "black"
}
}
}
}
这个答案很简单:
将窗格的属性padding
设置为0,这样就不会剩下任何边距了。您还可以单独设置所有填充(leftPadding…),这些属性从中继承 在您的示例中如下所示:
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Test")
RowLayout {
spacing: 0
anchors.margins: 0
anchors.fill: parent;
Pane {
anchors.margins: 0
id: menuPane
anchors.top: parent.top;
anchors.bottom: parent.bottom;
width: 200
padding: 0
ColumnLayout {
spacing: 0
anchors.fill: parent
anchors.margins: 0
Rectangle {
id: testRect
Layout.fillWidth: true
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
height: 20
color: "green"
}
}
Component.onCompleted: console.log(bottomPadding, leftPadding)
}
Pane {
anchors.margins: 0
anchors.left: menuPane.right
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
padding: 0
Rectangle {
anchors.margins: 0
anchors.fill: parent
color: "black"
}
}
}
}