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. QMainWindow doesn't resize when child widget gets resized
Forum Updated to NodeBB v4.3 + New Features

QMainWindow doesn't resize when child widget gets resized

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.5k 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.
  • S Offline
    S Offline
    sasmaster
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      [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.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sasmaster
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sasmaster
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            [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.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kenchan
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0

              • Login

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