Make centralWidget expanding
-
Hi,
I am trying to make the centralWidget of my MainWindow always use the full space of the window.
Inside my mainwindow.cpp:MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); view = new GraphicsView; setCentralWidget(view); view->setSizePolicy(QSizePolicy::Expanding); actualScene = new MyScene(); view->setScene(actualScene); }
But unfortunately I get this Errormessage:
C:\Qt\5.9.2\mingw53_32\include\QtWidgets\qsizepolicy.h:176: Fehler: 'constexpr QSizePolicy::QSizePolicy(int)' is private QT_SIZEPOLICY_CONSTEXPR QSizePolicy(int i) Q_DECL_NOTHROW : data(i) { } ^
Using a Layout instead gives the same Error:
view = new GraphicsView; QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(view); setLayout(layout); view->setSizePolicy(QSizePolicy::Expanding);
And without setting the SizePolicy, I even get:
QWidget::setLayout: Attempting to set QLayout "" on MainWindow "MainWindow", which already has a layout
Does anyone know what I am doing wrong?
PS: I found a lot of similar Questions, but most of them seemed to be solved using layouts.Thank you so much for any answer,
justStartedQt -
Hi
Mainwindow is special and has a widget called centralWidget in center.
you should set
layout on centralWidget and add view to the layout.
It will use all space pr default.You can do it very easy in Designer by
Open the mainwindow.ui file
1: Find Graphical view in list to the left
2: drag to the mainwindow
3: right click somewhere in mainwindow ( not on view)
4: select the layout menu in bottom and select the "layout vertically"the GraphicsView will then cover all of mainwindow and follow if you resize it.