如题。在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.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" } );
}
}
Button
{
anchors.left: testCombo.right
anchors.verticalCenter: testCombo.verticalCenter
anchors.margins: margin
text: qsTr( "clear list" )
onClicked:
{
testModel.clear( );
}
}
}
使用Qt 5.3.1的
Windows 8构建。
演示项目代码:这里
项目代码 ClearCheckBox.7z (2 K) 下载次数:3