QLineEdit
QString text () const
void setText ( const QString & )
QTextEdit
void setText ( const QString & )
QLCDNumber
void display ( const QString & s )
void display ( double num )
void display ( int num )
QComboBox
void addItem ( const QString & text, const QVariant & userData = QVariant() )
void addItem ( const QIcon & icon, const QString & text, const QVariant & userData = QVariant() )
void addItems ( const QStringList & texts )
int count () const
int currentIndex () const
QString currentText () const
QString str1,str2,str3;
str1="hello1";
str2="hello2";
str3="hello3";
QStringList longerList = (QStringList() << str1 << str2 << str3);
ui->comboBox->addItems(longerList);
QProgressBar
ui->progressBar->setMaximum(totalBytes); //最大值
ui->progressBar->setValue(bytesRead); //当前值
QCheckBox
void MainWindow::on_pushButton_clicked()
{
bool bl=ui->checkBox->checkState();
ui->checkBox->setChecked(!bl);
}
item widgets(item based)**************************************************************************************************************************************************
item based顾名思义就是用item为widgets赋值,所以要先创建item对象
QListWidget refer to help
QString str1,str2,str3;
str1="hello1";
str2="hello2";
str3="hello3";
QStringList longerList = (QStringList() << str1 << str2 << str3);
ui->listWidget->addItems(longerList);
new QListWidgetItem(tr("Oak"), ui->listWidget);
new QListWidgetItem(tr("Fir"), ui->listWidget);
new QListWidgetItem(tr("Pine"), ui->listWidget);
QListWidgetItem *newItem = new QListWidgetItem;
newItem->setText("itemText");
ui->listWidget->insertItem(0, newItem);
//插入到第2行
QTreeWidget refer to help
void MainWindow::on_pushButton_2_clicked()
{
QTreeWidgetItem *item = new QTreeWidgetItem;
item->setText(0,"hello");
ui->treeWidget->insertTopLevelItem(0, item);
//从第0项开始插入,从0算起
//ui->treeWidget->addTopLevelItem(item);
//追加在最后一项
ui->treeWidget->setHeaderLabel("hello");
}
void MainWindow::on_pushButton_clicked()
{
ui->treeWidget->setColumnCount(2);
//设置为两列
QList<QTreeWidgetItem *> items;
for (int i = 0; i < 10; ++i)
items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i))));
ui->treeWidget->insertTopLevelItems(0, items);
//ui->treeWidget->addTopLevelItems(items);
}
item widgets(item based)**************************************************************************************************************************************************
item views(model based)**************************************************************************************************************************************************
model based顾名思义就是用model 为views赋值,所以要先创建model 对象
QTableView
ui->tableView->setModel(model);
qt4 数据库操作---------tableView
item views(model based)**************************************************************************************************************************************************