Is there a way in Qt to add a layout or widgets to a QMenu
to create a custom menu?
The example below (left) is what I have, and I'd like to aim for something similar to the mock-up on the right, by adding non-menu widgets. If it can't be done by QMenu
, are there guides to produce similar results (perhaps by having a more standard widget act as a context menu) anywhere?
I wrote a script, you can try it.
but I am not subclass QMenu.
To customize menu items you can use
QWidgetAction
class. But you want to customize menu to look like popup widget. So you may subclassQMenu
and try to improve layout of menu for your needs (QMenu
isQWidget
). You questoin is not clear.Sure there is! In Qt, if there is a a will there is a way.
You will probably need to make your own class that uses
QMenu
and uses a memberQListWidget
.You will then need to generate the layout and overload all the correct
QLayout
functions for size recalculation.And then you'll need to use this layout (think
QHBoxLayout
) to display both aQMenu
and aQListWidget
side by side.That should be enough to point you in the right direction.
EDIT:
As a commenter pointed out, you can't inherit two
QObject
things so I updated the answer accordingly.