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);

   tree = new QTreeWidget(splitter);
   QTreeWidgetItem * topLevel= new QTreeWidgetItem();

   QTreeWidgetItem* treeItem = new QTreeWidgetItem();
   treeItem->setText(0, "Configuration Help");

   HelpBrowser* helpBrowser = new HelpBrowser(splitter);


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

Recommended Answers

I think you need to look at QSizePolicy (accessed from QWidget::sizePolicy()). Basically, the size policy is …

Jump to Post

All 3 Replies


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.

Thank You Mike. :) you always give me good solutions!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.