MainWindow doesnt show MenuBar
-
Created project with MainWindow shows only included Widget, but no MenuBar. Cant understand why, help me please.
Important Note: the same code works correctly on other machines, only on my computer it show wrong result.
The image demonstrate what i got instead of menu bar.
QMake version 3.0
Using Qt version 5.5.1
Ubuntu 16.04Below mainwindow.h
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QtGui> #include <QWidget> class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); ~MainWindow(); private: QMenu *file; }; #endif // MAINWINDOW_H
Below mainwindow.cpp
#include "mainwindow.h" #include <QtGui> #include <QtWidgets> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { //QVBoxLayout *vbl = new QVBoxLayout; QMenu *file = new QMenu("&File"); //menuBar()->addMenu("&File");//new QMenu("&File"); file->addAction("&Quit",qApp,SLOT(quit()),Qt::CTRL+Qt::Key_Q); QMenuBar *mb = menuBar(); mb->addMenu(file); mb->show(); setMenuBar(mb); //vbl->setMenuBar(mb); //setLayout(vbl); resize(400,400); } MainWindow::~MainWindow() { }
-
@Vadik YEEEEAH, solved, after some investigations and reinstalling of all components it turned out. Need to change in 'System Settings -> Appearance -> Behavior' parameter for 'Show the menus for a window' from the "In the menu bar" to "In the window's title bar". Thanks to everyone who tried to help.
-
@Vadik said in MainWindow doesnt show MenuBar:
mb->show();
vbl->setMenuBar(mb);
try to remove these lines
-
@medyakovvit
Won't he needsetMenuBar(sb)
for his main window too? -
@medyakovvit Already tried this, and many of other combination "removing-adding". No one helps
-
Hi,
Aren't you on Ubuntu ? If so, isn't your menu bar shown at the top of the screen macOS like ?
-
@Vadik YEEEEAH, solved, after some investigations and reinstalling of all components it turned out. Need to change in 'System Settings -> Appearance -> Behavior' parameter for 'Show the menus for a window' from the "In the menu bar" to "In the window's title bar". Thanks to everyone who tried to help.
-
@JNBarchan Question is solved, but as you asked.
I don't think it's needed as he gets pointer to menu bar with:QMenuBar *mb = menuBar();
and this function returns the menu bar that already set.
-
@medyakovvit
Yeah, I kinda mis-read (C++ not being my language) it as having been:QMenuBar *mb = new QMenuBar();
thinking he was creating his own new one which would need setting. Using the existing menubar and changing its content is of course preferable.