PDA

View Full Version : selecting a specific QtreeList item



MrGarbage
9th October 2007, 14:31
What is the proper method for changing the currently selected item in a QTreeList?

I've specified...
setSelectionMode(QAbstractItemView::SingleSelectio n);
setSelectionBehavior(QAbstractItemView::SelectRows );

I have a function called as shown below:

connect(m_treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
this, SLOT(changePage(QTreeWidgetItem *, QTreeWidgetItem *)));

In some cases I want to ignore the treeclick and Not have the treelist selection change.


void MainWindow::changePage(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
....

// Ignore click in tree and keep the selection on the currently selected item...
current->setSelected(false);
m_treeWidget->setCurrentItem(previous);
update();


}


This now selects everything between current and previous.

As I have called:

setSelectionMode(QAbstractItemView::SingleSelectio n);
setSelectionBehavior(QAbstractItemView::SelectRows );

I don't see how this should even be possible. I can't make multiple selections
or a range of selections manually from the tree...

wysota
9th October 2007, 14:45
Current item and selected item are two different concepts. You can connect to the selectionChanged signal of the item selection model (you have to retrieve it first from the view) and have both the old and new selections available. Then you can reapply the old selection if you want.