使用焦点和 popup.visible 播放时 ComboBox 上的奇怪行为

Strange behavior on ComboBox when playing with focus and popup.visible

当我尝试执行此代码时,我有一个奇怪的行为让我很烦:

import QtQuick 2.7
import QtQuick.Controls 2.0

ApplicationWindow {
    id: window
    visible: true
    width: 640
    height: 480

    Rectangle {
        color: "green"
        width: parent.width/2
        height: parent.height
        anchors.right : parent.right


        ComboBox {
            id:combo
            popup.visible: combo.activeFocus
            model: [ "Banana", "Apple", "Coconut" ]
        }

    }
    CheckBox {
        id:check
    }
}

如果我点击 CheckBox,然后点击 ComboBoxComboBox.popup 将在 1 毫秒内出现,然后消失 。 我不明白为什么因为 activeFocus = true

你知道为什么吗?

这种行为是意料之中的,如果您遵循导致它的事件链:

  1. 您点击了ComboBox
  2. ComboBox收益activeFocus
  3. ComboBox.popup变成visible
  4. 处理点击,切换可见性 -> ComboBox 变为不可见。

删除行

popup.visible: combo.activeFocus

你很好。

改为通过 open()close() 控制可见性。