QMenuBar: menu is hidden when moving window to another monitor
-
Hi ALL,
I am using MDI interface and trying to add QMenuBar and QToolBar to MDI Child window.
As the Qt designer allow to add menu and tool bar only to QMainWindow I am doing this in the code bacause QMdiSubWindow is inherited from QtWidget.
Here is the code.resize(300, 300);
QWidget* widget = new QWidget(this);
widget->show();QMenuBar *menuBar = new QMenuBar(widget);
QMenu *fileMenu = new QMenu("File");
menuBar->addMenu(fileMenu);
fileMenu->addAction("Save");
fileMenu->addAction("Exit");
QMenu *actionMenu = new QMenu("Action");
menuBar->addMenu(actionMenu);
actionMenu->addAction("Start");
actionMenu->addAction("Finish");menuBar->move(0, 0);
QToolBar* toolbar = new QToolBar(widget);
QIcon icon1("RED.ico");
toolbar->addAction(icon1,"OPEN");
QIcon icon2("YELLOW.ico");
toolbar->addAction(icon2,"CLOSE");QRect rect = menuBar->frameGeometry(); //getting the height of the menu strip to place tool bar below
int height = rect.height();
toolbar->move(0, height);setWidget(widget);
I am adding two icons to the tool bar.
Everything is looking fine but there is one problem.
I have two monitors. First with 2560 x 1440 resolution and second 1910 x 1080.
When the program launched on the first it looks fine. When I move it to the second it also looks fine.
When the program is launched on the second monitor it looks fine but when I move it to the first monitor i see this:But on another monitor i see this:
Menu of the child window is hidden. That only happens when program starts on the LowResolution monitor (second) and moved to HIgh resolution monitor (first).
I am not sure if i placed menu and tool bar correctly.
What is the problem?
thanks. -
Hi
I think its due to you forgot the layout as shown in the sample
https://forum.qt.io/topic/97803/qmdisubwindow-is-it-possible-to-add-menu-strip/3 -
@zulu
can't tell you exactly what is happening without proper debugging but anyway i think you want to achieve the following:MyMdiSubWindow::MyMdiSubWindow(QWidget* parent) : QMdiSubWindow(parent) { QMenuBar *menuBar = new QMenuBar(widget); // ... QToolBar* toolBar = new QToolBar(widget); // ... QVBoxLayout* layout = new QVBoxLayout; layout->addWidget( menuBar ); layout->addWidget( toolBar ); layout->addWidget( contentWidget, 1000 ); QWidget* widget = new QWidget( this ); widget->setLayout( layout ); setWidget(widget); }
-
Yes i have removed the QVBoxLayout beacuse I didn't get how to use it properly.
When i add menu and toolbar to it the toolbar is in the middle of the window.
So i guess i need to add an area below the toolbox. (Client area).
In this line we add something but i can't get what do we actually add:layout->addWidget( contentWidget, 1000 );
Could you explain?
@raven-worx said in QMenuBar: menu is hidden when moving window to another monitor:
contentWidget
-
@zulu said in QMenuBar: menu is hidden when moving window to another monitor:
Could you explain?
it just makes sure that the content (added with a stretch of 1000) "pushes" the other widgets in the layout to the top
-
@zulu
i assumed there will be later on.
If not, remove this line, or simply insert a empty widget (new QWidget
)