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. How to create central widget which does not expand on main window resize?

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.2k Views
  • 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 Offline
    H Offline
    H. Krishnan
    wrote on last edited by
    #1

    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
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on last edited by alex_malyu
      #2

      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
      0
      • H Offline
        H Offline
        H. Krishnan
        wrote on last edited by
        #3

        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
        0
        • A Offline
          A Offline
          alex_malyu
          wrote on last edited by
          #4

          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
          0

          • Login

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