You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, May 8th 2012, 8:18am

resizing child window with parent window

Please give me some idea on resizing the child window. I have parent widget, when resizing this parent widget, I want all my other child widgets should also resize accordingly.

I have tried with QFormLayout, with formlayout, the widget’s size is changing, e.g a pushbutton is coming horizontally as long as the parent widget, although I am specifying a size for 100,25 width and height.

Please give me some suggestion. Check this snippet.

Source code

1
2
3
4
5
6
7
8
9
10
11
MainWindow::MainWindow(QWidget *parent):QMainWindow(parent)
{
   setGeometry(0,0,600,400);
   QPushButton *button = new QPushButton(“Add chart”, this);
   button->setGeometry(5,5,100,25);
   button->show();

  QTextEdit *edit = new QTextEdit(this);
  edit->setGeometry(5, 35, width()-10, height()-40);
  edit->show();
}


This 2 controls are set on the widget, now when I resize to the full screen, the textedit size is not changing accordingly, please help what I can do for this. Thanks Sujan

2

Tuesday, May 8th 2012, 8:33am

the whole point of layouts is that you shouldnt really be hard coding geometries. If you still want to do this, then you need to add spacers and/or stretch

e.g. http://doc.qt.nokia.com/4.7-snapshot/qbo…html#addStretch
http://doc.qt.nokia.com/4.7-snapshot/qspaceritem.html

You said you used a QFormLayout - there are none used in that snippet.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

3

Tuesday, May 8th 2012, 9:01am

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
MainWindow::MainWindow(QWidget *parent):QMainWindow(parent)
{
   setGeometry(0,0,600,400);
   QPushButton *button = new QPushButton(“Add chart”, this);
   button->setGeometry(5,5,100,25);
   button->show();

  QTextEdit *edit = new QTextEdit(this);
  edit->setGeometry(5, 35, width()-10, height()-40);
  edit->show();

  QFormLayout *formL = new QFormLayout(this);
  formL->addWidget(edit);
  setLayout(formL);

}


See I have added a form layout, with this my edit is not changing when I resize the mainwindow. Please help

4

Tuesday, May 8th 2012, 3:38pm

try replace setLayout(formL); with
centralWidget()->setLayout(formL);

??
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.