1
我想设置我的QML应用程序窗口的最小宽度和高度,以便内容项完全可见(未剪裁)。QML ApplicationWindow:设置最小尺寸以适合内容
import QtQuick 2.5
import QtQuick.Controls 1.4
ApplicationWindow {
visible: true
width: 100
height: 100
title: "test"
minimumWidth: circle.width
minimumHeight: circle.height // + menuBar.height
menuBar: MenuBar {
Menu {
title: qsTr("File")
MenuItem {
text: qsTr("Exit")
onTriggered: Qt.quit();
}
}
}
Rectangle {
id: circle
anchors.centerIn: parent
width: 200
height: 200
color: "red"
radius: width * 0.5
}
}
下面是结果:
正如你所看到的,设置的最小宽度正常工作。最小高度似乎与菜单栏的高度有关。问题是,像menuBar.height
这样的东西不起作用,因为这个属性不存在。
所以,问题是:我怎么设置ApplicationWindow的大小,从而使内容项(由width
/height
或implicitWidth
/implicitHeight
给出)不会被截断?
注意:实际上,内容项目不是一个红色圆圈,而是一个游戏画布,我想动态调整大小。
作品:
因此,我们可以定义
ApplicationWindow
的高度本身。非常感谢! – enkelwor