Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove space (margin) that between QMainWindow and mdiArea?

Tags:

c++

qt

qt5

I have a QMainWindow and I have inserted mdiArea in the main window.
You must first see the following image:

As you seen the gray area is mdiArea and the spaces(margin) that between main window and mdiArea are what I want to remove it.
I have used setContentsMargins function, but does not do anything.

How can I remove these spaces ?

I want to be like the following image: enter image description here

like image 298
Lion King Avatar asked Jun 16 '14 08:06

Lion King


1 Answers

QMainWindow has a central widget that has a layout. The layout you use on QMainWindow is should be used upon its central widget instead. Hence you have to call

QWidget* QMainWindow::centralWidget() first,

so you can get the central widget first and then use

void QLayout::setContentsMargins(int left, int top, int right, int bottom)

to adjust its layout. The diagram below comes from Qt's documentation.

enter image description hereenter image description here

Creating a main window without a central widget is not supported. You must have a central widget even if it's just a placeholder.


For example, you could have the following in QMainWindow's constructor:

centralWidget()->layout()->setContentsMargins(0, 0, 0, 0);
statusBar()->hide();
ui->mainToolBar->hide();

enter image description here

The status bar and the tool bar have been hidden, in order to remove as much blank space as possible.

like image 132
Tay2510 Avatar answered Sep 18 '22 00:09

Tay2510