解决QML开发中ComboBox中一个已选择项没有清除的问题
2014-09-18 14:17
295 查看
解决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,因为数据库是只读的解决方法
- xcode替换同名图片后,显示的还是旧图片。各种清除缓存都没有解决问题
- Robotframework解决Selenium2Library中的select frame无法选择没有name也没有id的frame或者iframe的问题
- Android开发之如何在WebView中点击链接使用自身打开(解决出现的选择使用第三方应用的问题)
- 信息系统开发平台OpenExpressApp - 如何解决ComboBox.TextProperty绑定带来问题的来龙去脉
- 解决juqery easyui combobox只能选择问题
- Android系统驱动开发琐碎——解决spidev读写过程没有时钟信号的问题
- 开发Struts 2项目遇到的一个问题,就是在struts-tags标签库下没有了s:datetimepicker标签的解决办法
- 没有数据线,Wifi也能连接Android真机开发调试!彻底解决“无法识别的USB设备”等数据线连接问题!
- WPF开发中遇到的问题及解决系列(二):如何获取通过binding生成的ComboBox或者ListBox等的Item
- 开发Struts 2项目遇到的一个问题,就是在struts-tags标签库下没有了s:datetimepicker标签的解决办法
- 【COCOS2DX-LUA 脚本开发之十四】解决自定义cpp类通过tolua++ binding LuaCocos2d后编译到Android运行黑屏(没有调用自定义cpp类)的问题!
- 解决combobox没有item的特别tag的问题
- 绝大多数情况下,没有解决不了的问题,只有因为平时缺少练习而惧怕问题的复杂度,畏惧的心理让我们选择避让,采取并不那么好的方案去解决问题
- IOS开发问题解决之Xcode修改项目名称后,无法选择run的设备
- 编译类【COCOS2DX-LUA 脚本开发之十四】解决自定义CPP类通过TOLUA++ BINDING LUACOCOS2D后编译到ANDROID运行黑屏(没有调用自定义CPP类)的问题!
- 【问题解决】IDEA右键选择new新文件的时候没有JSP文件选项解决
- xcode6下没有模拟器选项,只能选择iOS Device选项的问题解决办法