QPushbutton loses its click event due to the set menu
-
Hi Guys!
I have a QPushbutton and i added a Qmenu to it. But this QPushbutton has a clicked event. When i clicked the button the menu is working but the event is not.
My code:QPushButton *pBackgroundImg= new QPushButton("Things"); pBackgroundImg->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); QAction *a1 = new QAction("1 item"); QAction *a2 = new QAction("2 item"); QAction *a3 = new QAction("3 item"); QMenu *menu = new QMenu; menu->addAction(a1); menu->addAction(a2); menu->addAction(a3); menu->setNoReplayFor(pBackgroundImg); pBackgroundImg->setMenu(menu); connect(pBackgroundImg,&QPushButton::clicked, [=] { pBackgroundImgClicked(); });
Any ideas?
-
Hi Guys!
I have a QPushbutton and i added a Qmenu to it. But this QPushbutton has a clicked event. When i clicked the button the menu is working but the event is not.
My code:QPushButton *pBackgroundImg= new QPushButton("Things"); pBackgroundImg->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); QAction *a1 = new QAction("1 item"); QAction *a2 = new QAction("2 item"); QAction *a3 = new QAction("3 item"); QMenu *menu = new QMenu; menu->addAction(a1); menu->addAction(a2); menu->addAction(a3); menu->setNoReplayFor(pBackgroundImg); pBackgroundImg->setMenu(menu); connect(pBackgroundImg,&QPushButton::clicked, [=] { pBackgroundImgClicked(); });
Any ideas?
@Kaguro
I guess it's an either-or: either you have a button with no menu actions and it has a clicked, or it has menu actions in which case the click is swallowed to open the menu.Why do you want the button click as well as the actions anyway? If you really, really have to, and you don't get a better answer, you might still be able to find the click via an
eventFilter
on something like the pushbutton, worth a try. -
Hi Guys!
I have a QPushbutton and i added a Qmenu to it. But this QPushbutton has a clicked event. When i clicked the button the menu is working but the event is not.
My code:QPushButton *pBackgroundImg= new QPushButton("Things"); pBackgroundImg->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); QAction *a1 = new QAction("1 item"); QAction *a2 = new QAction("2 item"); QAction *a3 = new QAction("3 item"); QMenu *menu = new QMenu; menu->addAction(a1); menu->addAction(a2); menu->addAction(a3); menu->setNoReplayFor(pBackgroundImg); pBackgroundImg->setMenu(menu); connect(pBackgroundImg,&QPushButton::clicked, [=] { pBackgroundImgClicked(); });
Any ideas?
The click on your button gets intercepted and opens your
QMenu
.
YourQPushButton
is still aQPushButton
but kinda lost the push-button behavior since it's now a menu button.This turns the button into a menu button, which in some styles will produce a small triangle to the right of the button's text.
-
The click on your button gets intercepted and opens your
QMenu
.
YourQPushButton
is still aQPushButton
but kinda lost the push-button behavior since it's now a menu button.This turns the button into a menu button, which in some styles will produce a small triangle to the right of the button's text.
@Pl45m4 said in QPushbutton loses its click event due to the set menu:
The click on your button gets intercepted and opens your QMenu.
Your QPushButton is still a QPushButton but kinda lost the push-button behavior since it's now a menu button.Oh i see! TY for your help! :)
-
Hi
Well it would be sort of confusing to the user if it still did its Clicked thing
as it would then open the menu, indicating its waiting for user input but
at the same did also did something in the background. -
@Pl45m4 said in QPushbutton loses its click event due to the set menu:
The click on your button gets intercepted and opens your QMenu.
Your QPushButton is still a QPushButton but kinda lost the push-button behavior since it's now a menu button.Oh i see! TY for your help! :)
-
Hi
Well it would be sort of confusing to the user if it still did its Clicked thing
as it would then open the menu, indicating its waiting for user input but
at the same did also did something in the background. -
@Pl45m4 said in QPushbutton loses its click event due to the set menu:
connect(menu, &QMenu::aboutToShow, ={
pBackgroundImgClicked();
});haha and it works! You are my hero!