PDA

View Full Version : Disable QTreeView item



tmmak
8th January 2011, 01:34
I created a QTreeView and then select an item of the view to create a second view that contains a subset of the original tree showing only the ancesters and offsprings of the selected item using QSortFilterProxyModel.

In the second view (NOT in the original view), I want to make the ancestors of the selected item un-selectable (grayed out). Is that possible?
Thanks in advance.

skyperhh
8th January 2011, 13:15
Hi,

use signal QTreeView::currentChanged and set current index as new QTreeView::setRootIndex of your second tree view. This shows you only the child's of your select item, or use QTreeView::setRootIndex(your_current_index.parent( )) for showing also the selected item.

Making the items in your second view un-selectable, you must change Qt::ItemFlags of your item .... make a ProxyModel for your treemodel, return all flags only Qt::ItemIsEnabled, map your index from first treeview with mapFromSource() as new rootItem for your second view with the proxy.

kosasker
1st February 2011, 08:33
Hi... I need a solution about this...

I'm making an app with Qt SDK 2010.05... I have a treeview widget. I just want to get current item index of selected item and save it to the registry.
After that i want to read current index from registry and select item as default



QString ipnum = ui->treeView->model()->index(ui->treeView->currentIndex().row(),2).data().toString();
int rowNum = ui->treeView->selectionModel()->currentIndex().row();
........................................
QSettings writedata("Encom", "Tron");
writedata.beginGroup("CLU");
writedata.setValue("interface_currentIndex",rowNum);
writedata.setValue("interface_ipnum",ipnum);
writedata.endGroup();

........................................

//I cant find that how can i set the saved row number, as default row after...
//im try to use the qmodelindex but i cant do it...




QModelIndex index = (0,0,QModelIndex());
ui->treeView->selectionModel()->setCurrentIndex(index,QItemSelectionModel::Select) ;


its not working too.. i cant understand it...