Results 1 to 9 of 9

Thread: Widget layout in GridLayout

  1. #1
    Join Date
    Dec 2009
    Posts
    12
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Question Widget layout in GridLayout

    Hello
    I'm just making my first steps in qt so don't laugh
    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
    Attached Images Attached Images

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Widget layout in GridLayout

    the last parameter in QGridLayout::addWidget is used for alignment.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following user says thank you to spirit for this useful post:

    Dato0011 (7th December 2009)

  4. #3
    Join Date
    Dec 2009
    Posts
    12
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Widget layout in GridLayout

    Thanks for the reply spirit
    Is there any way to set the alignment parameters from the designer?
    thanks again

  5. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Widget layout in GridLayout

    no, there is no such possibility.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. The following user says thank you to spirit for this useful post:

    Dato0011 (7th December 2009)

  7. #5
    Join Date
    Aug 2009
    Posts
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default 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
    Last edited by alpinista; 7th December 2009 at 09:03. Reason: spelling error

  8. The following user says thank you to alpinista for this useful post:

    Dato0011 (7th December 2009)

  9. #6
    Join Date
    Dec 2009
    Posts
    12
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default 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?
    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.

  10. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Widget layout in GridLayout

    Quote Originally Posted by Dato0011 View Post
    Yes you are right. from code it's more optimal.
    but does it mean that I have to create the gui from the code?
    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.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  11. The following user says thank you to spirit for this useful post:

    Dato0011 (7th December 2009)

  12. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Widget layout in GridLayout

    Quote Originally Posted by Dato0011 View Post
    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.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  13. The following user says thank you to spirit for this useful post:

    Dato0011 (7th December 2009)

  14. #9
    Join Date
    Dec 2009
    Posts
    12
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Widget layout in GridLayout

    Thank you very musch guys. I did it

Similar Threads

  1. changing layout of a widget
    By mikro in forum Qt Programming
    Replies: 10
    Last Post: 4th August 2009, 20:21
  2. QScrollArea: clearing the layout of the inner widget
    By mattc in forum Qt Programming
    Replies: 1
    Last Post: 3rd August 2009, 08:09
  3. hiding a widget without rearrange layout
    By mastupristi in forum Newbie
    Replies: 1
    Last Post: 6th July 2009, 17:20
  4. Resize widget force layout resizing
    By ^NyAw^ in forum Qt Programming
    Replies: 17
    Last Post: 11th February 2009, 11:27
  5. resizing events of a custom widget in a layout
    By Rooster in forum Qt Programming
    Replies: 7
    Last Post: 16th February 2008, 10:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.