【问题标题】:Qt Designer can't reference ApplicationWindow sizeQt Designer 无法引用 ApplicationWindow 大小
【发布时间】:2018-01-24 11:35:42
【问题描述】:

这是我在 stackoverflow 中的第一篇文章,所以我什至很难解释这个问题。

我开始在 Qt Designer 和 Creator 中为我的应用程序开发 UI。 考虑到可扩展性,我将所有应用页面设计为 ApplicationWindow 宽度和高度

当应用程序被构建但在 Qt 设计器中页面大小为 0 时,这可以正常工作。 所以我不能在设计器中使用它们。

有没有办法绕过它?

这是一个代码示例:

ma​​in.qml

ApplicationWindow {
        id: main_window
        visible: true
        width: 450
        height: 700
        minimumWidth: 450
        minimumHeight: 700

Page1.Form.ui.qml

Page {
    id: p_basicpage
    width: ApplicationWindow.width
    height: ApplicationWindow.height

构建应用程序后,它在可扩展性方面运行良好。 问题出在设计师身上:

【问题讨论】:

  • 引用主窗口属性的方式不对。您应该通过id 引用它,因此它应该被替换为width: main_window.width。但我建议您改用锚点:anchors.fill: parent
  • 您好,感谢您的提示。我试过width: main_window.width,但问题是一样的。页面不能有anchors.fill: parent 属性:/

标签: qt qml qtquick2 designer


【解决方案1】:

Page 确实有anchor.fill 属性,从文本编辑器(不是从Form Editor)设置它并去掉widthheight 属性:

Page {
   id: p_basicpage
   anchors.fill: parent

【讨论】:

  • 我强烈建议您不要使用 QML Designer,至少在您学习 QML 时是这样。
  • 您能否再澄清一下。那么,当我是 QML 的专业人士时,我应该只使用 Designer 吗?这不是很令人鼓舞。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-06-06
  • 2013-06-06
  • 2017-05-28
  • 2019-11-20
  • 2017-08-11
  • 1970-01-01
  • 2014-10-22
相关资源
最近更新 更多