qt - QML ComboBox 弹出问题
问题描述
我最近使用了很多组合框,但是在特定的弹出窗口中有一个问题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。
解决方案
查看自定义文档,我可以看到它根据弹出窗口是否可见有条件地设置模型。对您的代码段执行相同操作使其对我有用:
model: popup.visible ? comboNum.delegateModel : null
但是,Default 样式的实现ComboBox
并没有这样做,所以我不确定为什么在你的情况下它是必要的。
推荐阅读
- duplicates - 是否可以根据数据之间的时间间隔删除 Power BI 中的重复项?
- python - 如何使用 SSL 在 localhost 中运行烧瓶应用程序
- web-scraping - 如何在 scrapy_splash 中生成当前响应 URL
- vb.net - 使用 StringSplitOptions 获取单词列表 VB.NET
- c - 我正在尝试使用 C 代码在 MAC OS 中获取新连接的磁盘(笔式驱动器)MOUNT POINT
- objective-c - 当 macOS Catalina 中存在多个 NSScreen 时确定 NSScreen 上的鼠标光标 X 位置
- android - 在另一个活动中未从 RedirectUriReceiverActivity 收到 Intent
- angular - bpmn 图上的热图:错误类型错误:无法分配给对象“[object ImageData]”的只读属性“data”
- apache-spark - spark 分区大小是等于 HDFS 块大小还是取决于所有执行程序上可用的内核数?
- sql - 替换 SQL 查询中的子查询