0

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.
2
Contributors
3
Replies
24
Views
2 Years
Discussion Span
Last Post by myk45
Featured Replies
  • I think you need to look at [QSizePolicy](http://qt-project.org/doc/qt-4.8/qsizepolicy.html) (accessed from [QWidget::sizePolicy()](http://qt-project.org/doc/qt-4.8/qwidget.html#sizePolicy-prop)). 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 … Read More

2

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.