QTreeWidget

#include "dialog.h"
#include "ui_dialog.h"
#include<QtCore>
#include<QtGui> Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
ui->treeWidget->setColumnCount(2);
//ui->treeWidget->setHeaderLabel("Boat");
ui->treeWidget->setHeaderLabels(QStringList() << "one" << "two");
AddRoot("1 Hello","cat");
AddRoot("2 Hello","cat");
AddRoot("3 Hello","cat");
} Dialog::~Dialog()
{
delete ui;
} void Dialog::AddRoot(QString name,QString Description)
{
QTreeWidgetItem *itm = new QTreeWidgetItem(ui->treeWidget);
itm->setText(0,name);
itm->setText(1,Description);
//ui->treeWidget->addTopLevelItem(itm); AddChild(itm,"one","hello");
AddChild(itm,"two","world");
}
void Dialog::AddChild(QTreeWidgetItem *parent,QString name,QString Description)
{ QTreeWidgetItem *itm = new QTreeWidgetItem();
itm->setText(0,name);
itm->setText(1,Description);
parent->addChild(itm);
// ui->treeWidget->addTopLevelItem(itm);
} void Dialog::on_pushButton_clicked()
{
ui->treeWidget->currentItem()->setBackgroundColor(0,Qt::red);
ui->treeWidget->currentItem()->setBackgroundColor(1,Qt::blue);
}

  

上一篇:Win 2008 R2安装SQL Server 2008“性能计数器注册表配置单元一致性”失败的解决办法


下一篇:Php 数据类型