QWidgetAction not visible
-
Hm, that's odd.
This works for me:
class MyWidgetAction : public QWidgetAction { public: MyWidgetAction(QObject* parent = 0) : QWidgetAction(parent) {} QWidget* createWidget(QWidget *parent) { QProgressBar* pb = new QProgressBar(parent); pb->setRange(0,0); return pb; } }; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QMenu* trayMenu = new QMenu(this); MyWidgetAction* widgetAction = new MyWidgetAction(this); ui->mainToolBar->addAction(widgetAction); //without this works too trayMenu->addAction(widgetAction); QSystemTrayIcon* trayIcon = new QSystemTrayIcon(this); trayIcon->setContextMenu(trayMenu); trayIcon->show(); }Can you see any relevant differences with what you have?
-
Hello, I have same problem.
QWidgetAction * wa = new QWidgetAction(ui->menubar); QPushButton *btn = new QPushButton("abc"); wa->setDefaultWidget(btn); ui->menubar->addAction(wa);Not visible on ui. What is the problem here ?
-
Hello, I have same problem.
QWidgetAction * wa = new QWidgetAction(ui->menubar); QPushButton *btn = new QPushButton("abc"); wa->setDefaultWidget(btn); ui->menubar->addAction(wa);Not visible on ui. What is the problem here ?
Did you test the code of @Chris-Kawa ?
Which version of Qt are you using ?
On which OS ?
If Linux which desktop environment ?
Which window manager ? -
I did not see any thing, I want to use QMenuBar, not QToolBar
class MyWidgetAction : public QWidgetAction { public: MyWidgetAction(QObject* parent = 0) : QWidgetAction(parent) {} QWidget* createWidget(QWidget *parent) { QPushButton* pb = new QPushButton("abc"); return pb; } }; QMenu* trayMenu = new QMenu(this); MyWidgetAction* widgetAction = new MyWidgetAction(this); ui->menubar->addAction(widgetAction); trayMenu->addAction(widgetAction); QSystemTrayIcon* trayIcon = new QSystemTrayIcon(this); trayIcon->setContextMenu(trayMenu); trayIcon->show();Qt: 6.10.2
Os: Ubuntu 24
desktop environment : GNOME -
Can you check under KDE ?
-
@SGaist Why ? I use gnome. What is the different ?
-
@SGaist Why ? I use gnome. What is the different ?
@Joe-von-Habsburg they don't have the same design. Gnome is closer to macOS and handles menu bars differently from KDE. This could be one of the reason you don't get the result you are looking for.
-
thanks for your reply and explain