PDA

View Full Version : [SOLVED] How do I deselect all items in a model/view without emit a signal?



pir
18th May 2006, 08:23
Hi!

I have looked around the forum and can't find any topics about this, so either its simple to do it or I have missed it...

I have a QTreeView and a custom model and want to deselect all items in the view without emitting a signal. The reason for this is that I have slots reacting to the signals of
changes in the selection ( QitemSelectionModel::selectionChanged(selected,des electted) ) which mess things upp when I use QTreeView::clearSelection().

I've also tried QItemSelectionModel::reset(), but I can't make it do anything. The view doesn't change and there doesn't seem like anything is deselected...

/pir

lauranger
18th May 2006, 08:47
Why not just set a flag, call the deselection method you found and then reset the flag ?
In your slots you react or not according to the flag.

jpn
18th May 2006, 09:11
You can temporarily block signals:
bool QObject::blockSignals ( bool block ) (http://doc.trolltech.com/4.1/qobject.html#blockSignals)

pir
18th May 2006, 09:48
Thanks for the tips!

Currently I have a flag as the suggested. That works fine, but because I am so slobby it is verfy likely that I will forget about it and will cause problems in the future.

The block thing... is there any drawbacks with using that? It seems like a very nice way to handle problems like this. It can be a problem if there are more than one flag to check and update, so blocking signals seems like a nice way to avoid them.

One more thing, how do I set this topic as solved? I've seen that some topics have a [SOLVED] label when the author of the question have got answers that is sufficient for solving the problem.

thanks
/pir

KShots
18th May 2006, 17:48
Just edit your original post's title and put [SOLVED] into it