Reputation: 117
I have a simple application. In MainWindow's constructor I have:
_someWidget = new someWidgetClass(this);
_someWidget ->setFixedSize(700,700);
_someWidget ->move(50,50);
wid = new QWidget(this);
wid->move(800,800);
wid->setFixedSize(100,100);
centralWidget()->adjustSize();
adjustSize();
I would like to resize MainWindow like that, his right bottom corner should be the right bottom corner of the wid
, so I would like to resize MainWindow to his contents. But adjustSize
doesn't work.
I tried to add sizeHint()
method in someWidgetClass
and return his size, but this doesn't help too.
Upvotes: 0
Views: 1692
Reputation: 3883
you should set one layout for centralWidget
, For Example, I test it with QGridLayout
. then add your widget in that layout :
auto _someWidget = new QWidget(this);
_someWidget->move(50, 50);
_someWidget->setFixedSize(700, 700);
centralWidget()->layout()->addWidget(_someWidget);
auto wid = new QWidget(this);
wid->move(800, 800);
wid->setFixedSize(100, 100);
centralWidget()->layout()->addWidget(wid);
centralWidget()->adjustSize();
adjustSize();
about adjustSize Function :
Adjusts the size of the widget to fit its contents. This function uses sizeHint() if it is valid, i.e., the size hint's width and height are
>= 0
. Otherwise, it sets the size to the children rectangle that covers all child widgets (the union of all child widget rectangles). For windows, the screen size is also taken into account. If the sizeHint() is less than (200, 100) and the size policy is expanding, the window will be at least (200, 100). The maximum size of a window is 2/3 of the screen's width and height.
Upvotes: 2