javascript - 如何在 QML 的弹出窗口中排列项目?
问题描述
https://doc.qt.io/qt-5/qml-qtquick-controls2-popup.html
这是我尝试过的。我希望弹出窗口的矩形的内部矩形填满整个区域。左侧和顶部有一些间隙。
Window
{
visible: true
width: 1000
height: 1000
title: qsTr("Hello World")
Rectangle
{
id: dot
color:"blue"; radius: 100
height: 33
width: 33
MouseArea
{
anchors.fill: parent
onClicked: popup.open()
}
}
Popup
{
id: popup;
width: 114
height: 88
x: 100; y: 45
focus: true
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
Rectangle
{
color: "red";
anchors.fill: parent
ColumnLayout
{anchors.fill: parent
Rectangle{ height: 30; width: 100; border.color: "black"}
Rectangle{ height: 30; width: 100; border.color: "black"}
Rectangle{ height: 30; width: 100; border.color: "black"}
}
}
}
解决方案
您需要注意Popup
padding
, ColumnLayout spacing
。
间隙是由弹出窗口引起的padding
……如果您不想padding
将其设置为 0。
但即使是 0 padding
,
您将在右侧得到间隙 ..因为popup
width
(114) 由弹出窗口的 Rectangle 继承,但内部矩形设置为固定width
100 .. 因此出现 14 的间隙。
如果你修复它..你仍然必须考虑Columnlayout
间距..默认情况下不是0,这可能导致最后一个矩形延伸到Popup的矩形下方,因此clip
可以使用矩形;
例如,此代码按预期绘制矩形。
Popup
{
id: popup;
padding: 0
width: 114
height: 88
x: 100; y: 45
focus: true
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
Rectangle
{
color: "red";
anchors.fill: parent
ColumnLayout
{
anchors.fill: parent
Rectangle{ height:30; width: popup.width; border.color: "black"}
Rectangle{ height: 30; width: popup.width; border.color: "black"}
Rectangle{ height: 30; width: popup.width; border.color: "black"}
}
}
}
如果我想概括popup
和Columnlayout
默认值,我会考虑使用contentitem
它给出弹出窗口的矩形尺寸:例如:
Popup
{
id: popup;
width: 114
height: 29 * 3
x: 100; y: 45
focus: true
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
Rectangle
{
color: "red";
anchors.fill: parent
ColumnLayout
{
anchors.fill: parent
Repeater{
id: repeater
model: 3
Rectangle{ height: (popup.contentItem.height - parent.spacing*repeater.count)/repeater.count; width: popup.contentItem.width; border.color: "black"}
}
}
}
}
推荐阅读
- powershell - 如何让循环在 PowerShell 中每 1 秒计数 1?
- python - 'flask run' 从源目录运行时找不到代码,而 'python -m flask run' 成功
- c# - 移动时在摄像机前生成预制件
- php - 如何使用 codeigniter 将循环字段数据插入数据库
- angular6 - 如何发布动态表单数据?
- c++ - c ++ const全局变量的链接?
- reactjs - 为什么
- visual-studio - 为什么安装 Wear OS Intel x86 Atom 系统映像 v2 失败
- ionic-framework - Ionic 4 - 找不到管道
- ruby-on-rails - Rails 创建额外的创建动作并将新的重定向到它