|
#include "treewidgetbutton.h" |
|
#include "ui_treewidgetbutton.h" |
|
#include <QPushButton> |
|
#include <QTreeWidgetItem> |
|
#include <QDebug> |
|
#include <QList> |
|
#include <QLabel> |
|
|
|
TreeWidgetButton::TreeWidgetButton(QWidget *parent) : |
|
QDialog(parent), |
|
ui(new Ui::TreeWidgetButton) |
|
{ |
|
ui->setupUi(this); |
|
|
|
QTreeWidget *myTree = ui->treeWidget; |
|
|
|
// Push buttons to be added |
|
QPushButton *topLevelButton = new QPushButton("Top Level Button"); |
|
QPushButton *childButton1 = new QPushButton("Child Button 1"); |
|
QPushButton *childButton = new QPushButton("Child Button 0"); |
|
|
|
// Connecting the button signals with corresponding slots |
|
connect(childButton1, SIGNAL(clicked(bool)), this, SLOT(onchildButton1Clicked(bool))); |
|
connect(topLevelButton, SIGNAL(clicked(bool)), this, SLOT(onTopLevelButtonClicked(bool))); |
|
|
|
// Creating widgetitems |
|
QTreeWidgetItem *topLevelItem = new QTreeWidgetItem(); |
|
QTreeWidgetItem *childItem1 = new QTreeWidgetItem(); |
|
QTreeWidgetItem *childItem = new QTreeWidgetItem(); |
|
|
|
// Top level item having the next level item as the child |
|
topLevelItem->addChild(childItem1); |
|
topLevelItem->addChild(childItem); |
|
|
|
// Adding the Top Level Button to the tree |
|
myTree->addTopLevelItem(topLevelItem); |
|
|
|
// Adding the buttons |
|
myTree->setItemWidget(topLevelItem, 0, topLevelButton); |
|
myTree->setItemWidget(childItem1, 0, childButton1); |
|
myTree->setItemWidget(childItem, 0, childButton); |
|
|
|
} |
|
|
|
void TreeWidgetButton::onTopLevelButtonClicked(bool clicked) |
|
{ |
|
ui->whichButtonLabel->setText("Top Level Button was Clicked"); |
|
} |
|
|
|
void TreeWidgetButton::onchildButton1Clicked(bool clicked) |
|
{ |
|
ui->whichButtonLabel->setText("Child Button 1 was Clicked"); |
|
} |
|
|
|
TreeWidgetButton::~TreeWidgetButton() |
|
{ |
|
delete ui; |
|
} |