您的位置:首页
解决QML开发中ComboBox中一个已选择项没有清除的问题
2017-06-25 09:11
393 查看
解决QML开发中ComboBox中一个已选择项没有清除的问题
近期使用QML开发一个项目。须要使用ComboBox进行显示。当进行一个操作时,须要向ComboBox加入一个元素,当进行另外一个操作时。须要清除ComboBox里面的元素。可是在操作的过程中,出现了一个诡异的现象——ComboBox里面的已选择项并没有清除。
以下是程序的截图,能够看到。ComboBox中已选择项并没有删除。可是ComboBox中的候选项已经删除了。
我在QTCN上进行提问。后面再大家的努力下,最终把这个问题攻克了。
原来还须要一个操作:testCombo.currentIndex = -1。以下是我改动后的代码,代码能够非常好地执行。
import QtQuick 2.3 import QtQuick.Controls 1.2 ApplicationWindow { visible: true width: 640 height: 480 title: qsTr( "Clear CheckBox" ) menuBar: MenuBar { Menu { title: qsTr( "File") MenuItem { text: qsTr( "Exit" ) onTriggered: Qt.quit( ); } } } ListModel { id: testModel } ComboBox { id: testCombo anchors.centerIn: parent model: testModel textRole: "name" } property int margin: appendButton.height / 3 Button { id: appendButton anchors.right: testCombo.left anchors.verticalCenter: testCombo.verticalCenter anchors.margins: margin text: qsTr( "Append to list" ) onClicked: { testModel.append( { "name": "This is one" } ); testModel.append( { "name": "This is two" } ); testModel.append( { "name": "This is three" } ); testModel.append( { "name": "This is four" } ); testCombo.currentIndex = 0;// 修正Bug加入的 } } Button { anchors.left: testCombo.right anchors.verticalCenter: testCombo.verticalCenter anchors.margins: margin text: qsTr( "clear list" ) onClicked: { testCombo.currentIndex = -1;// 修正Bug加入的 testModel.clear( ); } } }
相关文章推荐
- 解决QML开发中ComboBox中一个已选择项没有清除的问题
- Delphi2007没有ActiveX Control开发向导的问题解决
- 开发环境下调试没有问题,发布后运行却提示无法更新数据库 *.MDF,因为数据库是只读的解决方法
- 开发Struts 2项目遇到的一个问题,就是在struts-tags标签库下没有了s:datetimepicker标签的解决办法
- 【问题解决】IDEA右键选择new新文件的时候没有JSP文件选项解决
- xcode6下没有模拟器选项,只能选择iOS Device选项的问题解决办法
- 信息系统开发平台OpenExpressApp - 如何解决ComboBox.TextProperty绑定带来问题的来龙去脉
- 使用cordova/phonegap 开发应用前请阅读,环境搭建,UI选择,低端机性能问题解决
- Qt[5.4]开发Android[安卓]Quick/QML Extension[扩展]库[.so]工程[项目]编译问题及解决办法
- 【COCOS2DX-LUA 脚本开发之十四】解决自定义cpp类通过tolua++ binding LuaCocos2d后编译到Android运行黑屏(没有调用自定义cpp类)的问题!
- WPF开发中遇到的问题及解决系列(二):如何获取通过binding生成的ComboBox或者ListBox等的Item
- 开发Struts 2项目遇到的一个问题,就是在struts-tags标签库下没有了s:datetimepicker标签的解决办法
- 开发Struts 2项目遇到的一个问题,就是在struts-tags标签库下没有了s:datetimepicker标签的解决办法
- 解决juqery easyui combobox只能选择问题
- 解决combobox没有item的特别tag的问题
- 绝大多数情况下,没有解决不了的问题,只有因为平时缺少练习而惧怕问题的复杂度,畏惧的心理让我们选择避让,采取并不那么好的方案去解决问题
- IOS开发问题解决之Xcode修改项目名称后,无法选择run的设备
- 编译类【COCOS2DX-LUA 脚本开发之十四】解决自定义CPP类通过TOLUA++ BINDING LUACOCOS2D后编译到ANDROID运行黑屏(没有调用自定义CPP类)的问题!
- Android系统驱动开发琐碎——解决spidev读写过程没有时钟信号的问题
- 解决Selenium2Library中的select frame无法选择没有名字,没有id的frame或者iframe的问题