标题:ComboBox在model删除后首项并没有删除
作者:彩阳
日期:2014-09-18 09:25
内容:
如题。在QML实际开发的时候遇到了这样一个诡异的错误。我暂时没有找到好的解决方法,可能是我孤陋寡闻了吧,如果大家有好的解决方法,麻烦立即告诉我,谢谢了!
下面是演示程序截图:点击append to list按钮,数据会被添加到testModel并且显示在testCombo中,但是点击clear list按钮,虽然TestCombo没有下拉选项了,但是首项还是存在,我想去掉首项,该如何做呢?
源代码:
import QtQuick 2.3
import QtQuick.Controls 1.2
ApplicationWindow
{
visible: true
width: 640
height: 480
title: qsTr("Hello World")
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.he ..
#1 [uidab 09-18 10:56]
testCombo.currentIndex = -1;
testModel.clear( );
这样改一下。
#2 回 uidab 的帖子 [robertkun 01-03 10:11]
uidab:testCombo.currentIndex = -1;
testModel.clear( );
这样改一下。 (2014-09-18 10:56)