QTreeWidget

Additionally if you just want to loop through the tree widgets selected items, then something like:

Source code

1
2
3
4
5
foreach( QTreeWidgetItem *item, treeWidget->selectedItems() ) {
for( int col = 0; col <>columnCount(); ++col ) {
qDebug() << "Item Text [" <<>text( col );
}
}

i used your code but cannt get any text..

help me how can change this :

Source code

1
qDebug() << "Item Text: " <<>text( col ); 


to QString ..

and how can i use your code with qt designer

Source code

1
2
3
4
void books::on_treeWidget_itemClicked(QTreeWidgetItem* item, int column)
{

}
Qt Designer is mainly to assist in building GUI interfaces, it's not a all inclusive builder for you applications. You will need to create you own header and source files to work with the ui files that the designer creates. Many of the examples I post do this.

The QTreeWidgetItem text( int ) returns a QString.
(e.g. QString itemStr = item->text( col ); )

To use qDebug, include the header in you source file:
#include

---------------------------

Bottom line is you can't do everything with just the Qt Designer.

thanks alot ...

im can not use your way...my Knowledge in qt is very low

However how can i use this way :
ui->lineEdit->setText(ui->treeWidget->currentItem()->text());


Not sure what answer your waiting for, but If designer has this function, then something like:

Source code

1
2
3
4
void books::on_treeWidget_itemClicked(QTreeWidgetItem* item, int column)
{
ui->lineEdit->setText( item->text( column ) );
}
link: http://www.qtcentre.org/threads/13216-QTreeWidget-selection
--------------
dy'

Comments