I'm trying to insert a QWidgetAction inside a QMenu, which will be used as a context menu for tray. When I do this, I only get an empty line inside my menu.
I'm using:
- Qt 5.5.1.
- Plasma 5 desktop environment (Linux).
Here is my code:
action = new QWidgetAction(0);
testw = new QWidget();
testl = new QLabel(QString("Test"), testw);
action->setDefaultWidget(testw);
menu.addAction(action);
trayIcon.setContextMenu(&menu);
If I use menu.addAction(QString("Test")); it is displayed properly.
All the variables are members of my class.
As long as you already have the menu shown then the problem is with extra widget you wrap the QLabel with. This is the way QWdigetAction usually works:
Also unsure of the life-cycle of these objects (the ownership) and why
menuandtrayIconare not pointers but you should be more clear about that. By default I always create UI objects withnewand pass the parent widget/object address to constructor though we can have those on stack as well (not flexible approach).