#include "dialog.h"
#include "ui_dialog.h"
#include <QtCore>
#include <QtGui>
ui(new Ui::Dialog)
{
ui->setupUi(this);
ui->treeWidget->setColumnCount(2);
ui
->treeWidget
->setHeaderLabels
(QStringList()<<
"one"<<
"two");
AddRoot("1 first","tree");
AddRoot("2 second","person");
AddRoot("3 third","man");
AddRoot("4 fourth","and last");
}
Dialog::~Dialog()
{
delete ui;
}
{
itm->setText(0,name);
itm->setText(1,Description);
AddChild(itm,"one","1111");
AddChild(itm,"two","2222");
}
{
itm->setText(0,name);
itm->setText(1,Description);
parent->addChild(itm);
}
void Dialog::on_pushButton_clicked()
{
ui->treeWidget->currentItem()->setBackgroundColor(0,Qt::red);
ui->treeWidget->currentItem()->setBackgroundColor(1,Qt::blue);
}
#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->setHeaderLabels(QStringList()<< "one"<<"two");
AddRoot("1 first","tree");
AddRoot("2 second","person");
AddRoot("3 third","man");
AddRoot("4 fourth","and last");
}
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);
AddChild(itm,"one","1111");
AddChild(itm,"two","2222");
}
void Dialog::AddChild(QTreeWidgetItem *parent,QString name, QString Description)
{
QTreeWidgetItem *itm =new QTreeWidgetItem();
itm->setText(0,name);
itm->setText(1,Description);
parent->addChild(itm);
}
void Dialog::on_pushButton_clicked()
{
ui->treeWidget->currentItem()->setBackgroundColor(0,Qt::red);
ui->treeWidget->currentItem()->setBackgroundColor(1,Qt::blue);
}
To copy to clipboard, switch view to plain text mode
Bookmarks