MainWindow
::MainWindow(QWidget *parent
){
top->setText(0,"top");
top2->setText(0,"top2");
niz->setText(0,"lower");
niz2->setText(0,"even lower");
tree->addTopLevelItem(top);
tree->addTopLevelItem(top2);
top2->addChild(lower);
niz->addChild(lower2);
layout->addWidget(tree);
layout->addWidget(label);
widget->setLayout(layout);
this->setCentralWidget(widget);
}
{
label->setText(item->text(0));
}
void MainWindow
::keyPressEvent(QKeyEvent* event
) {
if((event->key() == Qt::Key_Up) || (event->key() == Qt::Key_Down))
{
label->setText(tree->currentItem()->text(0));
}
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
tree = new QTreeWidget(this);
label = new QLabel(this);
QTreeWidgetItem *top = new QTreeWidgetItem(0);
top->setText(0,"top");
QTreeWidgetItem *top2 = new QTreeWidgetItem(0);
top2->setText(0,"top2");
QTreeWidgetItem *lower = new QTreeWidgetItem(0);
niz->setText(0,"lower");
QTreeWidgetItem *lower2 = new QTreeWidgetItem(0);
niz2->setText(0,"even lower");
tree->addTopLevelItem(top);
tree->addTopLevelItem(top2);
top2->addChild(lower);
niz->addChild(lower2);
QWidget *widget = new QWidget(this);
QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget(tree);
layout->addWidget(label);
widget->setLayout(layout);
this->setCentralWidget(widget);
connect(tree,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(treeClicked(QTreeWidgetItem*,int)));
}
void MainWindow::treeClicked(QTreeWidgetItem* item, int col)
{
label->setText(item->text(0));
}
void MainWindow::keyPressEvent(QKeyEvent* event)
{
if((event->key() == Qt::Key_Up) || (event->key() == Qt::Key_Down))
{
label->setText(tree->currentItem()->text(0));
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks