Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    How to create central widget which does not expand on main window resize?

    General and Desktop
    2
    4
    1940
    Loading More Posts
    • 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.
    • H
      H. Krishnan last edited by

      I have a main window with a central widget and a few dock widgets. I would like the central widget to maintain its size when the main window is resized. How can I achieve that? At present, when the main window is resized, the central widget gets resized while the dock widgets try to maintain their sizes. I even tried to set a fixed size for the central widget but even that does not help.
      I am using Qt 4.8.

      1 Reply Last reply Reply Quote 0
      • A
        alex_malyu last edited by alex_malyu

        you have to describe what happens to additional space.

        One of the possibility you have (dummy ) central widget which resizes, but such widget will have a child not in the layout.

        1 Reply Last reply Reply Quote 0
        • H
          H. Krishnan last edited by

          Consider this example:

          #include <QtGui/QMdiArea>  
          int main(int argc, char** argv) 
          {
              QApplication app (argc, argv);
              QMainWindow* w = new QMainWindow();
              QWidget *dummy = new QTextEdit();
              dummy->setFixedSize(QSize(100,100));
              w->setCentralWidget(dummy);
              w->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
              QDockWidget* consoleDock = new QDockWidget("console", w);
              consoleDock->setWidget(new QTextEdit());
              consoleDock->widget()->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
              QDockWidget* gDock = new QDockWidget("graphics", w);
              gDock->setWidget(new QMdiArea());
              gDock->widget()->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
              w->addDockWidget(Qt::RightDockWidgetArea, gDock);
              w->addDockWidget(Qt::BottomDockWidgetArea, consoleDock);
              w->show();
              app.exec();
              return 0;
          }
          

          I want only the dock widgets marked graphics and console to expand when the main window is expanded. How can I achieve that?

          1 Reply Last reply Reply Quote 0
          • A
            alex_malyu last edited by

            All I say below depends on my understanding and my knowledge.
            Both might be failing in this case.

            If you want docked widgets expanding you need to resize them manually when window is resized.
            Normally dock widgets do not change their size, only central widget area does.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post