PDA

View Full Version : QTreeWidget and QStackWidget



Paulo Fernando Pimenta
1st March 2011, 01:08
Hi,

I used Qtdesigner and put a QtreeWidget with several items, each on containing its subitems, and a QStackedWidget with several pages. What i need is to connect the clicked () action on the QTreeWidgetItem and then, make the correct page appear on the QSTackWidget. I tried to read the QTreeWidget doc, but i couldnt figure out how.
There's also this post http://www.qtcentre.org/threads/37218-Sample-code-to-use-QTreeWidget-and-QStackWidget, but it doesnt say much.

Thanks in advance for any help.

tbscope
1st March 2011, 04:26
http://doc.qt.nokia.com/4.7/qtreewidget.html#itemClicked
http://doc.qt.nokia.com/4.7/qstackedwidget.html#currentIndex-prop

Paulo Fernando Pimenta
1st March 2011, 16:51
http://doc.qt.nokia.com/4.7/qtreewidget.html#itemClicked
http://doc.qt.nokia.com/4.7/qstackedwidget.html#currentIndex-prop

Thanks for your answer. However, i still couldnt put those things to work properly. I will post my code :


//My Slot Connection defined in MainWindow.cpp. Contains the QTreeWidget and the QStackWidget

connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem*,int )),this,SLOT(showPage(QTreeWidgetItem*)));

// Public slot defition in Mainwindow.h

public slots:

void showPage(QTreeWidgetItem *itemArvore);
};

// My showPage() method definition inside MainWindow.cpp

void Mainwindow::showPage(QTreeWidgetItem *item){

ui->stackedWidget->show();
ui->stackedWidget->setCurrentIndex(1);
// second Page. Works Fine. My ideia is to use the select qtreewidget index as a integer parameter
qDebug() << "Item" << item->indexOfChild(item);

}


My qDebug() response is always -1. Is it possible to use the qTreewidgetItem index as a parameter for the stackedWidget->setCurrentIndex() function ?


Regards

mcosta
1st March 2011, 18:27
You can set for each QTreeWidgetItem a customData with QTreeWidgetItem::setData (an index or a pointer to page) and use it in slot