Results 1 to 6 of 6

Thread: QToolBar: How do you suppress the right-click menu that allows hiding the toolbar?

  1. #1
    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 QToolBar: How do you suppress the right-click menu that allows hiding the toolbar?

    How do you suppress the right-click menu that allows hiding a QToolBar ? The tool bars are part of a QMainWindow if that makes a difference.

    Should be a very simple thing to do but my searches in the documentation have drawn a blank. I can see where the label text can be set and can set it to an empty string but the right-click option remains.

    Cheers,
    Chris W
    Last edited by ChrisW67; 10th June 2010 at 06:28. Reason: More info

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QToolBar: How do you suppress the right-click menu that allows hiding the toolbar

    You can override QWidget::contextMenuEvent and ignore the event.
    That should I guess.

  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: QToolBar: How do you suppress the right-click menu that allows hiding the toolbar

    I fear it is too late by the time a context menu event has been sent. You did give me a hint that lead to:
    Qt Code:
    1. m_ui->toolBar->setContextMenuPolicy(Qt::NoContextMenu);
    2. // or
    3. m_ui->toolBar->setContextMenuPolicy(Qt::PreventContextMenu);
    To copy to clipboard, switch view to plain text mode 
    which I thought might work. The first but didn't seem to have any effect. The second stopped a context menu if clicked on the tool bar, but a context menu allowing hiding the tool bar would still come up if the right-click happened over the menu bar. I had to do:
    Qt Code:
    1. setContextMenuPolicy(Qt::NoContextMenu);
    To copy to clipboard, switch view to plain text mode 
    on the QMainWindow to stop both. Seems that the context menus on the menu and tool bars of a main window are delegated upward.

  4. #4
    Join Date
    Jun 2010
    Location
    India
    Posts
    50
    Thanks
    1
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Smile Re: QToolBar: How do you suppress the right-click menu that allows hiding the toolbar

    Just Override QMenu * QMainWindow::createPopupMenu ()

    QMenu * MyMainWindow::createPopupMenu ()
    {
    return NULL;
    }

  5. The following user says thank you to agathiyaa for this useful post:

    Lawand (27th March 2011)

  6. #5
    Join Date
    Dec 2010
    Location
    Israel
    Posts
    90
    Thanks
    59
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QToolBar: How do you suppress the right-click menu that allows hiding the toolbar

    Found a nice answer on StackOverflow. Just call:

    Qt Code:
    1. setContextMenuPolicy(Qt::NoContextMenu);
    To copy to clipboard, switch view to plain text mode 

    inside your QMainWindow subclass.

    http://stackoverflow.com/questions/6...lbar-unhidable

  7. #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: QToolBar: How do you suppress the right-click menu that allows hiding the toolbar

    That information was already in this thread two years ago

Similar Threads

  1. Hiding a QToolButton in a QToolBar
    By elcuco in forum Qt Programming
    Replies: 3
    Last Post: 24th November 2009, 20:35
  2. Hiding mac system menu in fullscreen mode
    By jupi32000 in forum Qt Programming
    Replies: 0
    Last Post: 18th November 2009, 19:32
  3. QToolBar double click
    By sdfisher in forum Qt Programming
    Replies: 4
    Last Post: 8th October 2007, 06:19
  4. ToolBar Action With Menu
    By indifference in forum Qt Programming
    Replies: 4
    Last Post: 10th September 2007, 19:37
  5. Toolbar show menu
    By Michiel in forum Qt Programming
    Replies: 5
    Last Post: 26th May 2007, 15:22

Tags for this Thread

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.