Results 1 to 3 of 3

Thread: QTableWidget + QEventFilter: cannot filter mouse events

  1. #1
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget + QEventFilter: cannot filter mouse events

    Hi all,

    I need to permit to edit only some items of the QTableWidget, not all, so I've thought to install an
    event filter but I'm not able to filter the mouse events. I log the event type but I've never seen a log
    with type 2, 3 or 4 (mouse events).

    This is my filter:

    Qt Code:
    1. bool CMouseEventFilter::eventFilter(QObject *Object, QEvent *Event)
    2. {
    3. if (Object->objectName() == "tbwHaiClients")
    4. {
    5. MainWindow::Log(Object->objectName() + ": " + QString().number(Event->type()));
    6.  
    7. switch (Event->type())
    8. {
    9. case QEvent::MouseButtonDblClick:
    10. case QEvent::MouseButtonRelease:
    11. case QEvent::MouseButtonPress:
    12. {
    13. // WILL DO SOME STUFF
    14. //return false;
    15. return true;
    16. }
    17. default: break;
    18. }
    19. }
    20. return false;
    21. }
    22. ////////////////////////////////////////////////////////////////////////////////
    To copy to clipboard, switch view to plain text mode 

    The filter works because I can see other event types like 1, 110, 8, 10, 11...
    What am I doing wrong ?

    Thanks.


    Added after 17 minutes:


    I've seen that if I install also:
    twClients->viewport()->installEventFilter(m_MouseEventFilter);

    I can see the mouse events but the problem is that I have several table widgets and all of them
    have the same name in the event filter function: "qt_scrollarea_viewport".
    How can I distinguish them ?
    Last edited by trallallero; 7th October 2011 at 14:35.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableWidget + QEventFilter: cannot filter mouse events

    If you want to make some of your items not editable then clear the Qt::ItemIsEditable flag from those items using QTableWidgetItem::setFlags().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    trallallero (8th October 2011)

  4. #3
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget + QEventFilter: cannot filter mouse events

    Is it so easy ? thanks a lot wysota

Similar Threads

  1. How to set filter option in QTableWidget
    By johnMick in forum Newbie
    Replies: 7
    Last Post: 18th October 2011, 14:41
  2. Replies: 3
    Last Post: 8th October 2011, 09:46
  3. Event filter with mouse events
    By felo188 in forum Qt Programming
    Replies: 13
    Last Post: 22nd July 2011, 10:57
  4. Replies: 2
    Last Post: 2nd April 2008, 14:19
  5. mouse moving don't produce mouse events
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2006, 06:13

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.