PDA

View Full Version : How to intercept the "show menu" button click on QToolButton menu button



mrchumley
9th May 2012, 15:33
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


{
....
myButton = new QToolButton(this);
myButton->setPopupMode(QToolButton::MenuButtonPopup);
connect(myButton, SIGNAL(clicked()), this, SLOT(slot_myButtonClicked()));

QMenu* myMenu = new QMenu(this);
pMyAction = new MyAction(this);
myMenu->addAction(pMyAction);
....
}

void MainWindow::slot_myButtonClicked()
{
pMyAction->setEnabled(.....);
myButton->showMenu();
}




TIA

MrC

mentalmushroom
11th May 2012, 10:28
connect the menu's aboutToShow signal to your own updateMenuActions slot and do what you want with the actions in that slot.

mrchumley
11th May 2012, 10:38
Good solution, worked a treat,

thanks

MrC