Adding Menu Bar with no result..
-
wrote on 3 May 2024, 19:26 last edited by
-
Works fine for me:
#include <QtWidgets> int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::AA_DontUseNativeDialogs); QMainWindow mainWin; mainWin.menuBar()->addMenu(new QMenu("Preferences")); mainWin.show(); return app.exec(); }
-
Lifetime Qt Championwrote on 3 May 2024, 19:39 last edited by Christian Ehrlicher 5 Mar 2024, 19:40
Please do not post images but actual text - it's unreadable.
What I can see is that you create a second QMenuBar for unknown reasons. Use the one from QMainWindow or properly set the QMenuBar to the QMainWindow. -
wrote on 3 May 2024, 20:05 last edited by
Right, thanks... im sorry.. just put an image to illustrate result app window and code...
-
wrote on 3 May 2024, 20:10 last edited by
The image posted is perfectly readable and sufficient to illustrate the problem. Why do you question OP reason for adding the second menubar ? His reasoning is immaterial to help resolve the issue. Perhaps edit your post to concentrate / expand on your valid , axtual solutions . ( I wrote this while the OP replied ).
-
The image posted is perfectly readable and sufficient to illustrate the problem. Why do you question OP reason for adding the second menubar ? His reasoning is immaterial to help resolve the issue. Perhaps edit your post to concentrate / expand on your valid , axtual solutions . ( I wrote this while the OP replied ).
@AnneRanch said in Adding Menu Bar with no result..:
Why do you question OP reason for adding the second menubar
Because he does and I also properly explained what's wrong - sorry if it's to complicated for you to understand.
-
wrote on 3 May 2024, 20:20 last edited by
Thanks for answering..
I have tryied using the default menuBar(),
Header:
#ifndef WPRINCIPAL_H #define WPRINCIPAL_H #include <QMainWindow> class QMenu; class QAction; class wprincipal : public QMainWindow{ Q_OBJECT private: QMenu* menu0 {nullptr}; //File... QAction* act00 {nullptr}; //File -> Preferences... protected slots: void ontrigger_act00(); public: explicit wprincipal(QWidget* _p = nullptr); ~wprincipal(){} }; #endif // WPRINCIPAL_H
Source:
#include "wprincipal.h" #include <QMenuBar> #include <QMenu> wprincipal::wprincipal(QWidget* _p) : QMainWindow(_p){ act00 = new QAction; act00->setText("Preferences"); menu0 = new QMenu; menuBar()->addMenu(menu0); menu0->addAction(act00); } void wprincipal::ontrigger_act00(){ }
...but still something happens that is not being shown:
-
Works fine for me:
#include <QtWidgets> int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::AA_DontUseNativeDialogs); QMainWindow mainWin; mainWin.menuBar()->addMenu(new QMenu("Preferences")); mainWin.show(); return app.exec(); }
-
wrote on 3 May 2024, 20:26 last edited by
Oops, thats weird... i see no big difference between both codes...
i will isolate the problem in a new project..
thanks. -
@1XU7 : I also don't see a big difference so can't tell what's wrong.
-
wrote on 4 May 2024, 02:54 last edited by
Missed the Title (you wrote it in constructor)
menu0 = new QMenu("File"); //or menu0 = new QMenu; menu0->setTitle("File");
If i miss the title, then bar is not being shown..
Thanks.
-
1/10