1 Attachment(s)
Widget layout in GridLayout
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 :)
Re: Widget layout in GridLayout
the last parameter in QGridLayout::addWidget is used for alignment.
Re: Widget layout in GridLayout
Thanks for the reply spirit :)
Is there any way to set the alignment parameters from the designer?
thanks again :)
Re: Widget layout in GridLayout
no, there is no such possibility.
Re: Widget layout in GridLayout
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 :)
Re: Widget layout in GridLayout
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.
Re: Widget layout in GridLayout
Quote:
Originally Posted by
Dato0011
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.
Re: Widget layout in GridLayout
Quote:
Originally Posted by
Dato0011
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.
Re: Widget layout in GridLayout
Thank you very musch guys. I did it :D