2

我正在使用 Qt 5.7 和 QtQuick.Controls 2.0。我想让我ComboBox的默认打开。为了做到这一点,我只是简单地设置popup.visible为 true,但不幸的是,我在控制台中收到以下错误:QML Popup: cannot find any window to open popup in.. 单击我的 ComboBox 打开和关闭它就好了,没有任何错误消息。我什至尝试过Component.onCompleted: _popup.open(),我的 ComboBox 中的 Popup 组件在哪里,但出现了相同的错误消息_popupid

编辑1(添加一个简单的例子):

ApplicationWindow {
  width: 200
  height: 200

  Item {
    anchor.fill: parent

    ComboBox {
      popup.visible: true
      model: ["First", "Second", "Third"]
    }
  }
4

1 回答 1

1

更新到 Qt 5.7.1 为我解决了这个问题,感谢@BaCaRoZzo 的建议!

编辑1:

作为一个旁注,我想补充一点,如果您收到消息QML Popup: cannot find any window to open popup in.,它也可能由于 Popup 组件找不到它的父级而发生。例如,如果在 StateMachine 的 State 中创建 Popup,就会发生这种情况。在这种情况下,您必须显式设置parentPopup! 的属性!

于 2017-01-17T17:20:24.857 回答