Hi All,

            1)It's easy to create a window in QT that the user can resize, but when they make the window bigger, all the contents stay where they were in the top left hand corner. They don't grow with the window. 
     2)Also when the window is launched the size of the window itself is very small. It has to be resized everytime to view the contents.

    Here is my code Snippet:

   QGroupBox *groupBox;
   QHBoxLayout *horizontalLayout;
   QSplitter *splitter;

   groupBox = new QGroupBox(this);
   horizontalLayout = new QHBoxLayout(groupBox);
   splitter = new QSplitter(groupBox);
   splitter->setOrientation(Qt::Horizontal);

   tree = new QTreeWidget(splitter);
   tree->setObjectName(QString::fromUtf8("tree"));
   QTreeWidgetItem * topLevel= new QTreeWidgetItem();
   topLevel->setText(0,"HELP");

   QTreeWidgetItem* treeItem = new QTreeWidgetItem();
   treeItem->setText(0, "Configuration Help");
   topLevel->addChild(treeItem);
   tree->addTopLevelItem(topLevel);
   splitter->addWidget(tree);

   HelpBrowser* helpBrowser = new HelpBrowser(splitter);
   splitter->addWidget(helpBrowser);

   horizontalLayout->addWidget(splitter);


How do i resize the window size itself first and also resize the window to fit to its contents? Please Help.

I think you need to look at QSizePolicy (accessed from QWidget::sizePolicy()). Basically, the size policy is what allows you to specify how widgets should grow automatically when their parent widget (with a layout) resizes, and things like their minimum / preferred size (e.g., to force to parent widget to adopt sufficient size to display its contents).

I don't know exactly the programmatic steps to do this, because I mostly create my GUIs in Qt Designer, where you can set all those things in the menus and property editors, which is much easier.

For resizing the main window, I would presume you either just use the size property, or you rely on the size policy, as I just mentioned.

This article has been dead for over six months. Start a new discussion instead.