QToolButton::showMenu() as wrapper of virtual function
-
Hi!
I need to generate dynamically menu shown by
QToolButton
. Current implementation doesn't allow this becauseshowMenu()
is slot. I'll be great to make it wrapper over virtual function, so old behavior would be preserved and menu could be customized before its appearance. -
Hi!
I need to generate dynamically menu shown by
QToolButton
. Current implementation doesn't allow this becauseshowMenu()
is slot. I'll be great to make it wrapper over virtual function, so old behavior would be preserved and menu could be customized before its appearance.@Eugene-Zelenko Can you explain your use case?
You set the menu using https://doc.qt.io/qt-5/qtoolbutton.html#setMenu before calling showMenu(). -
@Eugene-Zelenko Can you explain your use case?
You set the menu using https://doc.qt.io/qt-5/qtoolbutton.html#setMenu before calling showMenu().@jsulm
QToolButton
is added ascornerWidget
toQTabWidget
to show list of all tabs (in some cases long and not fitting screen) to switch between them. Currently code keeps track of tab insertions and removals to keepQToolButton
menu updated. However, it'll be much easier to generate menu on demand when button clicked. Current implementation ofQToolButton
doesn't allow it because of limitations described in original post. -
Hi
And you cant just replace the corner widget using
https://doc.qt.io/qt-5/qtabwidget.html#setCornerWidget
and then connect to slot when clicked and there show a menu ? -
Hi
And you cant just replace the corner widget using
https://doc.qt.io/qt-5/qtabwidget.html#setCornerWidget
and then connect to slot when clicked and there show a menu ?@mrjj
showMenu
is called inQToolButton::mousePressEvent
before call of baseQAbstractButton::mousePressEvent
with subsequentQAbstractButtonPrivate::emitPressed
(in Qt 5.14.2). -
@mrjj
showMenu
is called inQToolButton::mousePressEvent
before call of baseQAbstractButton::mousePressEvent
with subsequentQAbstractButtonPrivate::emitPressed
(in Qt 5.14.2).@Eugene-Zelenko
ok. and QToolButton::showMenu() was more code than i expected so
to fully support orientation etc its a bit of work.I was wondering if an event filter could let us handle the menu but i guess not.
It's very unlikely they would change it to be virtual but feel free to open an enhancement report on
https://bugreports.qt.io/secure/Dashboard.jspa -
@mrjj said in QToolButton::showMenu() as wrapper of virtual function:
It's very unlikely they would change it to be virtual
At least not before Qt7 :)
-
Maybe override QToolButton::mousePressEvent(), update your menu and call the base class impl then.
-
Maybe override QToolButton::mousePressEvent(), update your menu and call the base class impl then.
@Christian-Ehrlicher Aren't buttons could be pressed with keyboard? I think it's better to have single entry point than re-implement multiple event handlers.
-
@Eugene-Zelenko
ok. and QToolButton::showMenu() was more code than i expected so
to fully support orientation etc its a bit of work.I was wondering if an event filter could let us handle the menu but i guess not.
It's very unlikely they would change it to be virtual but feel free to open an enhancement report on
https://bugreports.qt.io/secure/Dashboard.jspa@mrjj Enhancement request had been opened.
-
You can also modify the menu when the reason for the menu change changes. Your suggestion will most likly die somewhere in the next few years so you have to find a solution now.
-
You can also modify the menu when the reason for the menu change changes. Your suggestion will most likly die somewhere in the next few years so you have to find a solution now.
@Christian-Ehrlicher As I wrote, I have working solution, but it's not most elegant one.