Results 1 to 3 of 3

Thread: How to intercept the "show menu" button click on QToolButton menu button

  1. #1
    Join Date
    Mar 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to intercept the "show menu" button click on QToolButton menu button

    I have a QToolButton with the style QToolButton::MenuButtonPopup so that it has a drop down arrow alongside the button which shows a menu when clicked.

    I want to disable one of the actions in the menu when its shown depending on the state of the system. I can catch the click on the toolbutton itself by connecting the clicked() signal to a slot and disabling the action there. But how do I connect to the click on the arrow button?

    Or is it better to make the action responsible for its state and listen to system changes?


    my existing code is along the lines of
    Qt Code:
    1. {
    2. ....
    3. myButton = new QToolButton(this);
    4. myButton->setPopupMode(QToolButton::MenuButtonPopup);
    5. connect(myButton, SIGNAL(clicked()), this, SLOT(slot_myButtonClicked()));
    6.  
    7. QMenu* myMenu = new QMenu(this);
    8. pMyAction = new MyAction(this);
    9. myMenu->addAction(pMyAction);
    10. ....
    11. }
    12.  
    13. void MainWindow::slot_myButtonClicked()
    14. {
    15. pMyAction->setEnabled(.....);
    16. myButton->showMenu();
    17. }
    To copy to clipboard, switch view to plain text mode 




    TIA

    MrC

  2. #2
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: How to intercept the "show menu" button click on QToolButton menu button

    connect the menu's aboutToShow signal to your own updateMenuActions slot and do what you want with the actions in that slot.

  3. #3
    Join Date
    Mar 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to intercept the "show menu" button click on QToolButton menu button

    Good solution, worked a treat,

    thanks

    MrC

Similar Threads

  1. Replies: 3
    Last Post: 8th December 2011, 20:21
  2. "Change widget class on button click" problem
    By utkozanenje in forum Newbie
    Replies: 3
    Last Post: 23rd May 2011, 01:40
  3. Implementing an "open recently opened files" menu?
    By joelthelion in forum Qt Programming
    Replies: 3
    Last Post: 6th March 2009, 11:49
  4. Replies: 2
    Last Post: 2nd April 2008, 18:28

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.