Results 1 to 5 of 5

Thread: How to disable context menu of a toolbar in QMainApplication

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2007
    Location
    Warsaw, Poland
    Posts
    52
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to disable context menu of a toolbar in QMainApplication

    Something like this?

    MWin inherits QMainWindow

    Qt Code:
    1. bool MWin::eventFilter(QObject* object, QEvent* event) {
    2. if(event->type() == QEvent::ContextMenu) {
    3. QContextMenuEvent* mevent = static_cast<QContextMenuEvent *>(event);
    4. if(mevent->reason() == QContextMenuEvent::Mouse) {
    5. qDebug("I have blocked the context menu.");
    6. return true;
    7. } else return QObject::eventFilter(object, event);
    8. }
    9. else return QObject::eventFilter(object, event);
    10. }
    To copy to clipboard, switch view to plain text mode 

    and installation:

    Qt Code:
    1. ...
    2. fileToolBar->installEventFilter(this);
    3. ...
    4. modeToolBar->installEventFilter(this);
    5. ...
    6. actionToolBar->installEventFilter(this);
    7. ...
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to disable context menu of a toolbar in QMainApplication

    More like this. You must test for the objects you're installing the filter for.
    Qt Code:
    1. bool MWin::eventFilter(QObject* object, QEvent* event) {
    2. if(event->type() == QEvent::ContextMenu &&
    3. ( object == fileToolbar || object == modeToolBar ... ) ) {
    4. QContextMenuEvent* mevent = static_cast<QContextMenuEvent *>(event);
    5. if(mevent->reason() == QContextMenuEvent::Mouse) {
    6. qDebug("I have blocked the context menu.");
    7. return true;
    8. } else
    9. return false;
    10. }
    11. else
    12. return QObject::eventFilter(object, event);
    13. }
    To copy to clipboard, switch view to plain text mode 


    Regards

Similar Threads

  1. Context Menu on QTableWidget
    By ankurjain in forum Qt Programming
    Replies: 9
    Last Post: 17th December 2009, 09:52

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.