Results 1 to 5 of 5

Thread: Implementation of right click for Vertical/Horizontal Headers in QTable

  1. #1
    Join Date
    Sep 2006
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Question Implementation of right click for Vertical/Horizontal Headers in QTable

    Greetings,

    I am using Qt 3.3.2.
    I am working with QTable.
    I find that there is no right clicked signal for the verticalHeader and horizontalHeader for tables.
    There is only left clicked signal for the headers.

    Now, I would like to know if there is a way to implement right click feature for the vertical and horizontal headers for tables.

    Thanks in advance.

  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: Implementation of right click for Vertical/Horizontal Headers in QTable

    Apply an event filter on the QHeader object (you can access it using QTable::verticalHeader() and QTable::horizontalHeader() and process its mousePressEvent.

  3. #3
    Join Date
    Sep 2006
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Implementation of right click for Vertical/Horizontal Headers in QTable

    Hi,
    I tried installing event filter on horizontal header for QTable.
    Something like this...

    Qt Code:
    1. class MyTable : public QTable
    2. {
    3. public:
    4. MyTable(QWidget* parent, const char* name);
    5. }
    6.  
    7. MyTable::MyTable(QWidget* parent, const char* name):QTable(parent,name)
    8. {
    9. horizontalHeader ()->installEventFilter(this);
    10. }
    11.  
    12. bool MyTable::eventFilter(QObject *pTarget, QEvent *pEvent)
    13. {
    14. if (pTarget == horizontalHeader())
    15. {
    16. if (pEvent->type() == QEvent::MouseButtonRelease)
    17. {
    18. QMouseEvent *pMouseEvent = (QMouseEvent *)pEvent;
    19. if (pMouseEvent->button() == Qt::RightButton)
    20. {
    21. qWarning(" vertical header right clicked!! ");
    22. // do something
    23. }
    24. }
    25. }
    26.  
    27. return QObject::eventFilter(pTarget, pEvent);
    28. }
    To copy to clipboard, switch view to plain text mode 

    When i righclick on horizontal header of my table, it is getting caught!. But, my table is not displaying any information ( data in cells ) that it used to before installing event filter on
    horizontal header
    Some light please!
    Last edited by wysota; 27th September 2006 at 16:30. Reason: missing [code] tags

  4. #4
    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: Implementation of right click for Vertical/Horizontal Headers in QTable

    Return false (or better yet QTable::eventFilter) from the filter when you process the event so that QHeader can do processing of its own.

    And don't return QObject::eventFilter if you don't process the event yourself. You should return the base class implementation, QTable::eventFilter() in this case.

  5. #5
    Join Date
    Sep 2006
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Thumbs up Re: Implementation of right click for Vertical/Horizontal Headers in QTable

    Hi !
    It worked!
    Thanks :-)

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.