View Full Version : Widget layout in GridLayout
Dato0011
7th December 2009, 08:27
Hello
I'm just making my first steps in qt so don't laugh :D
I want to control widget's alignment which is in gridlayout's cell. the problem is that when I place a widget in the layout, it is positioned in the center, vertically and horizontally. How can I change it's position, for example to top, bottom, left, right etc.? See the image in the attachement. The button "Centered" is in the center of the cell, I want it to be on the top. How can I achieve that?
Thanks :)
spirit
7th December 2009, 08:37
the last parameter in QGridLayout::addWidget is used for alignment.
Dato0011
7th December 2009, 08:42
Thanks for the reply spirit :)
Is there any way to set the alignment parameters from the designer?
thanks again :)
spirit
7th December 2009, 08:47
no, there is no such possibility.
alpinista
7th December 2009, 09:02
You can do it in Qt Designer, but it's a little tricky.
1. Insert a VBox layout to the cell where the button "centered" should be.
2. Insert a button to this layout.
3. Insert a vertical spacer below the button (still inside the VBox layout)
But anyway, I would do it in the code :)
Dato0011
7th December 2009, 09:14
Yes you are right. from code it's more optimal.
but does it mean that I have to create the gui from the code? :confused:
or does the designer generates "QGridLayout::addWidget" somewhere when I add a widget on the form? If so I'll be able to update that code.
spirit
7th December 2009, 09:19
Yes you are right. from code it's more optimal.
but does it mean that I have to create the gui from the code? :confused:
or does the designer generates "QGridLayout::addWidget" somewhere when I add a widget on the form? If so I'll be able to update that code.
no, you can create GUI using designer and then you can get access to a layotu in code and set properly alignment.
spirit
7th December 2009, 09:21
or does the designer generates "QGridLayout::addWidget" somewhere when I add a widget on the form? If so I'll be able to update that code.
yes. uic generates proper code according to created ui in the Qt Designer. just take a look into "ui_<class_name>.h" file.
Dato0011
7th December 2009, 09:26
Thank you very musch guys. I did it :D
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.