标题:【提问】对于QComboBox,不知有没有什么好办法动态生成列表内容
作者:yfy002
日期:2005-08-09 17:12
内容:
在qt的文档里没有看到清除QComboBox列表内容的方法。
目前我的做法是
首先setMaxCount(0);
一些操作
setMaxCount(num)
这样就把列表框清空了,然后根据需要再insert进去,不知有没有什么别的好方法??
#1 [XChinux 08-09 17:32]
确实没提供一个合适的接口.最方便的话,是使用QStringList最方便了.
main.cpp
#include "dlg.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
myDialog *dlg = new myDialog();
return dlg->exec();
}
dlg.h
#ifndef _DLG_H_
#define _DLG_H_
#include
#include "ui_combobox.h"
class myDialog:public QDialog
{
Q_OBJECT
public:
myDialog();
~myDialog();
private slots:
void buttonInsert();
void buttonDelete();
void comboBoxSelect(QString);
void comboBoxSelect(int);
private:
Ui::Form *ui;
};
#endif //_DLG_H_
dlg.cpp
#include "dlg.h"
myDialog::myDialog()
{
ui = new Ui::Form();
ui->setupUi(this);
connect(ui->PushButtonInsert, SIGNAL(clicked()), this, SLOT(buttonInsert()));
connect(ui->PushButtonDelete, SIGNAL(clicked()), this, SLOT(buttonDelete()));
connect(ui->ComboBoxTest, SIGNAL(activated(QString)), this, SLOT(comboBoxSelect(QString)));
connect(ui->ComboBoxTest, SIGNAL(activated(int)), this, SLOT(comboBoxSelect(int)));
}
myDialog::~myDialog()
{
}
void myDialog::buttonInsert()
{
//QMessageBox::information(this, tr("Information"), tr("Alert"), QMessageBox::Ok);
ui->ComboBoxTest->clear();
ui->ComboBoxTest->addItems(QStringList()
#2 [yfy002 08-23 16:32]
原来是有函数的阿,呵呵
4.0.1
- QComboBox
Made removeItem() and setRootModelIndex() visible in the
documentation.