标签:col name world tree eve script style child color
1、listWidget列表
在构造函数里面添加:
1 for (int i=0; i<9; i++) 2 { 3 ui->listWidget->addItem(QString::number(i)+"item here"); 4 }
在pushbutton里面添加
1 void Dialog::on_pushButton_clicked() 2 { 3 // QListWidgetItem *itm = ui->listWidget->currentItem(); 4 // itm->setText("Fuzzy Bunny of doom"); 5 // itm->setTextColor(Qt::red); 6 // itm->setBackgroundColor(Qt::black); 7 8 ui->listWidget->currentItem()->setText("Fuzzy Bunny of doom"); 9 ui->listWidget->currentItem()->setTextColor(Qt::red); 10 ui->listWidget->currentItem()->setBackgroundColor(Qt::black); 11 }
2、QTreeWidget
现在dialog.h里面声明两个新的函数
1 void AddRoot(QString name, QString Description); 2 void AddChild(QTreeWidgetItem *parent, QString name, QString Description);
在在dialog.cpp里面实现这两个函数
1 void Dialog::AddRoot(QString name, QString Description) 2 { 3 QTreeWidgetItem *itm = new QTreeWidgetItem(ui->treeWidget); 4 itm->setText(0,name); 5 itm->setText(1,Description); 6 ui->treeWidget->addTopLevelItem(itm); 7 8 AddChild(itm, "one", "hello"); 9 AddChild(itm, "two", "world"); 10 } 11 12 void Dialog::AddChild(QTreeWidgetItem *parent, QString name, QString Description) 13 { 14 QTreeWidgetItem *itm = new QTreeWidgetItem(); 15 itm->setText(0,name); 16 itm->setText(1,Description); 17 parent->addChild(itm); 18 }
在Dialog的构造函数中加入
1 ui->treeWidget->setColumnCount(2); 2 AddRoot("1 Hello","1 world"); 3 AddRoot("2 Hello","2 world"); 4 AddRoot("3 Hello","3 world");
标签:col name world tree eve script style child color
原文地址:https://www.cnblogs.com/dadidelearning/p/9579963.html