Results 1 to 7 of 7

Thread: Veto QT slot execution

  1. #1
    Join Date
    Nov 2015
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Veto QT slot execution

    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?

    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Veto QT slot execution

    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,
    _

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Veto QT slot execution

    If you do not want clicking an item in the view to select anything then call the view's QAbstractItemView::setSelectionMode() with QAbstractItemView::NoSelection

  4. #4
    Join Date
    Nov 2015
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Veto QT slot execution

    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?

  5. #5
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Veto QT slot execution

    Quote Originally Posted by rakeshthp View Post
    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.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Veto QT slot execution

    Quote Originally Posted by rakeshthp View Post
    @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()).

  7. #7
    Join Date
    Nov 2015
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Veto QT slot execution

    @ChrisW67:

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

Similar Threads

  1. Questions about slot execution.
    By skimmer in forum Newbie
    Replies: 4
    Last Post: 13th September 2012, 14:34
  2. One question about the execution of the slot function
    By charlse in forum Qt Programming
    Replies: 3
    Last Post: 26th April 2012, 11:21
  3. Signal/Slot execution sequences/preemption
    By xenome in forum Qt Programming
    Replies: 8
    Last Post: 17th September 2009, 23:40
  4. execution in QT
    By adamatic in forum Qt Programming
    Replies: 4
    Last Post: 20th February 2009, 09:12
  5. Execution error
    By Shuchi Agrawal in forum Installation and Deployment
    Replies: 10
    Last Post: 9th February 2007, 13:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.