Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Make centralWidget expanding

Make centralWidget expanding

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    justStartedQt
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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.

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved