It's not the same. When the size hint changes (for example becomes smaller) my code will resize the widget. Yours won't. One is dynamic, the other is static.
It's not the same. When the size hint changes (for example becomes smaller) my code will resize the widget. Yours won't. One is dynamic, the other is static.
To Wysota:
Ok, you're right:
( it's from qlayout.cpp , in function activate ).Qt Code:
case SetFixedSize: // will trigger resize mw->setFixedSize(totalSizeHint()); break;To copy to clipboard, switch view to plain text mode
But I believe both approaches will have the same effect on the attached dialog because from what I can see in the attachments, none of the widgets are resized dynamically, once the dialog is made visible.
OK, you got me![]()
Thanks to all who replied.
I added:
Qt Code:
To copy to clipboard, switch view to plain text mode
at line 40 of ui.cpp but now I get a very tiny window which shows nothing. I am now unable to resize the window which would be good except I can't see anything at all.
I also don't understand why setting the sizePolicy to Fixed isn't enough to do this.
Because your ui doesn't have a layout set.
I have attached the fixed version. Try it. Should work now...
I just set a vertical layout to your window.
Regards.
Last edited by marcel; 14th April 2007 at 08:58.
jamadagni (14th April 2007)
Thanks it works, but I still have a few questions:
- I created the UI file using Designer. Is it a designer bug that it did not create a layout object?
Should setSizePolicy(Fixed) not be enough to declare the window of fixed-size? After all that is the definition of Fixed:
QSizePolicy Class Reference:
QSizePolicy::Fixed : 0 : The QWidget::sizeHint() is the only acceptable alternative, so the widget can never grow or shrink (e.g. the vertical direction of a push button).- Why does Qt Designer not use this method itself?
- Why does Qt Designer by default create a centralWidget(QWidget) and layoutWidget(QVBoxLayout)? What is their use?
1. No, it is not a bug. You should layout your widgets.
As Wysota pointed out, QMainWindow is not a regular widget. It does not have a parent widget, therefore no layout to manage it's size and position.
2. Not sure what you mean? Do you mean why there isn't an option to set the size constraint? Maybe because the designer doesn't know the actual (runtime) contents of the widgets and this would mix things up ( could give you a wrong preview of the dialog ).
3. Probably just for preview reasons. But that shouldn't make things worse for you. You can always break the layout and set another one.
Regards
Of course I have laid-out my widgets. See the red line?
If that is the case, then it should use its child layout to manage its size, no? A QMainWindow never has a parent widget, but is in need of a size-controller. Ergo it should use the first child size-controller it finds.As Wysota pointed out, QMainWindow is not a regular widget. It does not have a parent widget, therefore no layout to manage it's size and position.
Yes, but you haven't cvreated a layout for the main window. Look at the ui I attached. The contents of the window stretch to fill the available space when you resize the window.Of course I have laid-out my widgets. See the red line?
Yes, use the layout of the window to set it's size. That's why setSizeConstraint worked.If that is the case, then it should use its child layout to manage its size, no? A QMainWindow never has a parent widget, but is in need of a size-controller. Ergo it should use the first child size-controller it finds.
Regards
OK thanks. I also succeeded with just removing the superfluous layoutWidget item and not adding another layout item. There already exists a layout within the layoutWidget item (which is now deleted) which I used. I also did some trimming by removing the SizePolicy items in the UI file since they are not used now.
A few final questions:
- If this is the correct thing to do then why did not Designer do this itself? Is this a bug?
- What is the use of the sizePolicy property of the QMainWindow, seeing as setting it to fixed does not give us anything?
- Finally, I presume you did the corrections you did using a text editor and not Designer, right?
1. No, I don't believe it's a bug. Looking at the UI the way it is now, you could have done it like this from the beginning.
2. No effect at all. It's a method from QWidget and applies to a lot of other widgets.
3. No, I did the correction with Designer. Right click in the form -> Lay out -> Lay out Vertically. No text editor, and you shouldn't use one.
nleverin (11th July 2007)
Size constraint is an attribute of a layout, not of the widget. I think it would be nice to be able to have such a property in designer just like we have margin and spacing available, but let's face it - how often do you set a size constraint on a layout?
You can't set a new layout for a main window.You can always break the layout and set another one.
No. Layout manages children, not parents. Period. What would happen if you'd wrap a widget with a layout and children into another layout? Which layout should be responsible for managing the size? Besides, you have to have something "fixed" at some point, otherwise you couldn't use size policies as any widget with "expanding" size policy would cause the top level widget to expand to screen width/height.
Why not? I used a QMainWindow as a child widget a few times...A QMainWindow never has a parent widget,
The window manager is its controller as it is a child of the root window of your screen.but is in need of a size-controller. Ergo it should use the first child size-controller it finds.
Designer uses a generic way of managing properties. If you wanted to hide properties which were unusable for top-level widgets, you'd have to have a way of marking any property as such and there would be a problem if you wanted to place one form inside another as the widget which was designed as a top-level widget might in the end be a child of some other widget.
You should never modify Designer generated files by hand.Finally, I presume you did the corrections you did using a text editor and not Designer, right?
Bookmarks