QMainWindow doesn't resize when child widget gets resized



  • I have the following problem.I have a QmainWindow which sets main layout and a widget added to that Layout.
    When I resize the widget the QmainWindows remains the same size.

    Here is the setup:
    In the QmainWindow:
    @

     this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    
    m_mainLayout = new QVBoxLayout();
    m_mainLayout->setAlignment(Qt::AlignHCenter);
    
    m_centralWidget = new QWidget();
    
    m_centralWidget->setLayout(m_mainLayout);
    setCentralWidget(m_centralWidget);
    
    this->setMinimumSize(800,600);
    
    m_mainLayout->addWidget(m_GLWidget);
    

    @

    Then,at some point m_GLWidget signals it needs to be resized.QmainWindow catches the signal and

    reized the m_GLWidget:

    @

    void MainWindow::ResizeViewportSlot(int w,int h){

      m_GLWidget->setFixedSize(w,h);
    
      m_GLWidget->updateGeometry();
    
      this->updateGeometry();
    

    }

    @

    So as I said.The main window doesn't get resized.What am I doing wrong here?
    Thanks.


  • Moderators

    [quote author="sasmaster" date="1419353342"]
    @
    this->setMinimumSize(800,600);
    @
    [/quote]Did you resize m_GLWidget to something smaller than 800x600?

    By the way, I don't think this is related to your problem but "QOpenGLWidget":http://doc.qt.io/qt-5/qopenglwidget.html has replaced QGLWidget in Qt 5.4. You should use that class if possible.



  • No,I resize m_GLWidget to the bigger than 800x600 size.Also ,I am still on Qt 5.2.1 version.



  • I found that if I remove this :

    @ this->setMinimumSize(800,600);@

    Then the MainWindos does get resized.But in such a case when the app is launched the initial window is collapsed to the area of controls which I don't want.I need on the start up to have it with some default width and height.


  • Moderators

    [quote author="sasmaster" date="1419410751"]I found that if I remove this :

    @ this->setMinimumSize(800,600);@

    Then the MainWindos does get resized.[/quote]Hmm, that sounds strange. Could you please submit a report to https://bugreports.qt-project.org/ and include your test code?

    [quote]But in such a case when the app is launched the initial window is collapsed to the area of controls which I don't want.I need on the start up to have it with some default width and height.[/quote]You can call the resize() function when you first create the window.



  • so what does your main function look like? It is easiest to use move and resize as soon as you create a window. If it's a main window that is probably best done in main but that depends on your flow.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.