【问题标题】:QML ComboBox Popup IssueQML ComboBox 弹出问题
【发布时间】:2018-06-02 06:28:36
【问题描述】:

我最近使用了很多组合框,但是在特定ComboBox 的弹出窗口中存在问题,我无法找到以下代码的确切问题:

import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.2

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    ComboBox{
        id:comboNum
        width:parent.width * 0.30
        height:parent.height * 0.15
        model: ["12","23","78","23","45","70"]
        currentIndex: 0

        popup: Popup{
            id:popup
            y: comboNum.height - 1
            width: comboNum.width
            height: comboNum.height * 2
            padding: 1

            contentItem: ListView {
                id: listview
                implicitHeight: popup.height
                clip: true
                model:comboNum.delegateModel
                currentIndex: comboNum.highlightedIndex
                interactive: true
                highlightMoveDuration: 0
                boundsBehavior: ListView.StopAtBounds

                ScrollBar.vertical:ScrollBar {}
            }
        }
    }
}

弹出窗口没有显示所有元素,我使用的是 QT 5.9.1。

【问题讨论】:

    标签: qt qml qtquick2 qcombobox


    【解决方案1】:

    查看customisation docs,我可以看到它根据弹出窗口是否可见有条件地设置模型。对你的 sn-p 做同样的事情会让它对我有用:

    model: popup.visible ? comboNum.delegateModel : null
    

    但是,Default style implementation of ComboBox 不这样做,所以我不确定为什么在你的情况下它是必要的。

    【讨论】:

    • 哦,这有点奇怪。我从没想过这会是个问题。将尝试弄清楚我们为什么要这样做!基于可见性
    猜你喜欢
    • 1970-01-01
    • 2019-02-12
    • 1970-01-01
    • 1970-01-01
    • 2011-12-13
    • 1970-01-01
    • 2021-11-20
    • 2011-06-18
    • 1970-01-01
    相关资源
    最近更新 更多