PDA

View Full Version : Veto QT slot execution



rakeshthp
21st January 2016, 12:42
Hello,

I am using QTreeWidget in my application. I need to perform some operation on selecting a particular item of the tree. There are three columns. By default when I click on any of the column of the QTreeWidgetItem, the entire item gets selected. What I want is when I click on the second column of the item, the code related to the second column should be executed, but the item should not get selected/highlighted.

The problem is the code is in the itemClicked slot. I want to interrupt the slot execution. I tried putting return statement, which still selected the item. Is there any option to stop selecting the Item, after executing my code? Something like vetoing the event as explained here (http://docs.wxwidgets.org/trunk/classwx_close_event.html)?

Thanks in advance

anda_skoa
21st January 2016, 18:20
A slot invocation is a method call, not an event.
If you don't want the signal to be emitted, override the view's mouse event handling.

Cheers,
_

ChrisW67
21st January 2016, 20:42
If you do not want clicking an item in the view to select anything then call the view's QAbstractItemView::setSelectionMode() with QAbstractItemView::NoSelection

rakeshthp
22nd January 2016, 04:43
Hi

@anda_skoa:
QTreeView has mouseEvent as non-virtual. So I cannot override the mouse-events of treeview.

@ChrisW67:
I guess that will be applicable for entire item. Not for a particular column of an item. Isn't it?

yeye_olive
22nd January 2016, 09:28
QTreeView has mouseEvent as non-virtual. So I cannot override the mouse-events of treeview.
Not sure what method you are referring to. I can see lots of specialized mouse*Event() methods, but no generic mouseEvent(). They all seem inherited from QWidget, and virtual.

ChrisW67
22nd January 2016, 21:02
@ChrisW67:
I guess that will be applicable for entire item. Not for a particular column of an item. Isn't it?
The selection behaviour is for the entire view (anything using the same selectionModel(), usually just the one view)

You complain that when the user clicks on an item in column 2 the entire row is selected, implying you want selection but you definitely do not want a selectionBehavior() of QAbstractItemView::SelectRows. You then say you do not want the item they clicked on to be selected either, so QAbstractItemView::SelectItems is not appropriate. It seems you want nothing at all selected by clicking in the view and therefore a selectionMode() of QAbtractItemView::NoSelection seems a good option.

If you want particular items scattered through a model to not be selectable then have the model return a flags() value for the affected indexes that does not contain Qt::ItemIsSelectable (or use a proxy to filter flags()).

rakeshthp
25th January 2016, 11:01
@ChrisW67:

Item should be selected if column 1 is clicked, and it should not get selected if column 2 is clicked. Is it possible?