aarelovich aarelovich - 2 months ago 43
C++ Question

Is it possible to remove borders a single QWidget around a QMainWindow?

This is a very simple problem to reproduce. Create a new project with Qt Creator with a

QMainWindow
. Using designer add a single widget (it doesn't matter which one) and then use the right button to set a layout (any layout as with a single widget the results are always the same).

There will be a gray border around the widget. I would like to remove this border so that the widget occupies the entirety of the main window area (which Qt always names
centralWidget
). Basically the single widget is all I want to see.

Is this possible? If so, how?

Answer

Yes, it's possible. All you need is setting margins of that centralWidget to 0. (note that you should first set up a layout)

In properties panel set the following properties to 0.

  • layoutLeftMargin
  • layoutTopMargin
  • layoutRightMargin
  • layoutBottomMargin

enter image description here


Also note that using a QWidget (not QMainWindow) as your main app window is perfectly valid, so if your app has only one widget, you won't need a QMainWindow at all. It's enough to show that widget.