Results 1 to 17 of 17

Thread: Putting Widgets into a Layout

  1. #1
    Join Date
    Feb 2009
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Putting Widgets into a Layout

    I've got a few widgets (a PushButton, CheckBox and ScrollBar) that I need to put into a window, aligned at the bottom. In my fiddling around with the Grid and Box layouts, the widgets always get piled on top of each other, or squished into a corner, or end up with really odd dimensions. How can I hardcode size and location values for each of them and then add them to the window?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Putting Widgets into a Layout

    You can but it's not advised, so I won't tell you how

    Instead use QBoxLayout::addStretch(), QBoxLayout::addSpacing() and size policies to place the widgets inside a layout correctly. If you provide an image of a mockup of what you want to achieve, we'll help you with that.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2009
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Putting Widgets into a Layout



    That's pretty much it. The drawing part is easy, but the widgets are a pain, and I haven't even attempted to display the picture.

    Help would be greatly appreciated.

  4. #4
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Putting Widgets into a Layout

    Try smth like this
    Qt Code:
    1. QGridLayout *layout = new QGridLayout;
    2.  
    3. layout->addWidget(Graphic, 0, 0, 1, 3);
    4. ...
    5. layout->addWidget(PushButton, 2, 0);
    6. layout->addWidget(CheckBox, 2, 2);
    To copy to clipboard, switch view to plain text mode 
    I'm a rebel in the S.D.G.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Putting Widgets into a Layout

    Quote Originally Posted by jcoop View Post


    That's pretty much it. The drawing part is easy, but the widgets are a pain, and I haven't even attempted to display the picture.

    Help would be greatly appreciated.
    Here is a UI file with what you want to achieve. Be sure to view it with a style that supports full styling (every style except WindowsXP, WindowsVista and Aqua) to see the colours from your mockup.
    Attached Files Attached Files
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Mar 2009
    Location
    California, USA
    Posts
    31
    Thanks
    2
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default My Layout Problems

    I am also have some trouble learning to do layouts in Qt Creator. I have included the ui file I am working on. By applying the grid layout to the whole form, I have gotten a lot closer to what I am attempting to do. The form does now resize correctly, for the most part. My problem is that I want the table widget on the left and its pushbuttons to not resize, while the right table and its pushbuttons will expand when resized. Is this possible? Or should I be content with what I have.

    I would appreciate any assistance. I am keeping notes on the information I am getting on using layouts and I hope to create a topic on the wiki to help us 'newbies' get up to speed on this.

    The file I have uploaded does not have any layouts applied.

    gary

    ps: I am not as smart as the trolls, but I do like lutefisk.

    http://www.davethefox.com/words/0112lutefisk.htm
    Attached Files Attached Files
    Last edited by Chisum; 14th April 2009 at 17:45. Reason: spelling error

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Putting Widgets into a Layout

    Is this what you wanted? Note the size policy of the left view and the size constraint of the layout it is placed in.

    In general read about layouts and size policies.
    Attached Files Attached Files
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Chisum (14th April 2009)

  9. #8
    Join Date
    Mar 2009
    Location
    California, USA
    Posts
    31
    Thanks
    2
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Putting Widgets into a Layout

    Well, I have continued to work on my layout problems and I have created a version which is very close to what I want. I have included it below. A quick review of some things I learned include:

    It is possible to teach an 'old dog' new tricks but it does take time.

    I will expand on my work over the next few days, and share it with all of you newbies. My goal is to provide an easy to follow set of steps to achieve this.

    I do have a few issues with the documentation in Qt Assistant. Specifically, when choices like (Fixed, Preferred. et al) are not really explained. For starters, examine the Size Policy values.

    Now, it is time to kick back...

    gary
    Attached Files Attached Files

  10. #9
    Join Date
    Mar 2009
    Location
    California, USA
    Posts
    31
    Thanks
    2
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Putting Widgets into a Layout

    Just a more personal thank you to wysota. I was composing my last post when you posted yours. My wife is Polish-American, so we have great love and respect for all things Polish. I really do love this site, it is one of the best programming sites I have seen.

    Good Luck with your studies and work.

    gary

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Putting Widgets into a Layout

    Quote Originally Posted by Chisum View Post
    I do have a few issues with the documentation in Qt Assistant. Specifically, when choices like (Fixed, Preferred. et al) are not really explained. For starters, examine the Size Policy values.
    They are explained here and there but I understand it may not be very clear for everybody. I've been meaning to prepare a video tutorial on layouts and size policies but I either lack motivation or time. When (if) I have both at the same time, I'll post the results.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #11
    Join Date
    Mar 2009
    Location
    California, USA
    Posts
    31
    Thanks
    2
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Cool Re: Putting Widgets into a Layout

    wysota - I would like to write up a wiki type how-to on some of the basics of using layouts, particularly using layouts in Qt Creator. It would provide some of the basic information I have learned from my experiences with Designer. I enjoy colloborative efforts and I have the time to do it.

    gary

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Putting Widgets into a Layout

    Please do that but don't mention "Qt Creator". Creator is just a wrapper over Designer when it comes to designing user interfaces so it's better to say "Designer" than "Creator" in this context.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #13
    Join Date
    Mar 2009
    Location
    California, USA
    Posts
    31
    Thanks
    2
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default First Attempt at an explanation of layouts

    wysota:

    I uploaded the file below to the wiki. Not sure I did it correctly, so here is a rough draft of the file as well. Please feel free to edit it, brutally if necessary.

    Also any one else who might what to change or add to it, please feel free to do so.

    It is my first attempt at a wiki article.

    gary
    Attached Files Attached Files

  15. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: First Attempt at an explanation of layouts

    What wiki did you put it in? It's not our wiki for sure, it hasn't been updated for two weeks...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #15
    Join Date
    Mar 2009
    Location
    California, USA
    Posts
    31
    Thanks
    2
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Wink Re: Putting Widgets into a Layout

    wysota

    I went to the Wiki shown at the top of the forum, logged in, and then went to the 'Uploadfile' page, and then completed the form. I really have not done a page on a wiki before. Where should I go? It sounds like I need to write up my experiences with 'Creating My First Page' for the wiki. lol

    It may be that I screwed up the 'Destination filename'. I did add a brief summary.

    gary
    Last edited by Chisum; 17th April 2009 at 17:48. Reason: updated contents

  17. #16
    Join Date
    Mar 2009
    Location
    California, USA
    Posts
    31
    Thanks
    2
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Putting Widgets into a Layout

    wysota

    Well, I have created a page within my 'user talk' and saved it. I am still not clear if that is the right way to create a page.

    gary

  18. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Putting Widgets into a Layout

    It's not

    Follow this link:
    http://wiki.qtcentre.org/index.php?s...+with+Designer
    and click on "Create this page".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Custom Widgets and layout managers...
    By TemporalBeing in forum Qt Programming
    Replies: 6
    Last Post: 4th March 2009, 13:48
  2. Custom widgets in layout
    By Palmik in forum Newbie
    Replies: 11
    Last Post: 26th January 2009, 12:08
  3. Replies: 3
    Last Post: 27th November 2008, 23:57
  4. Moving widgets within a layout.
    By importantman in forum Qt Programming
    Replies: 6
    Last Post: 26th May 2007, 20:21
  5. Promoted widgets and layout boxes
    By notsonerdysunny in forum Qt Tools
    Replies: 3
    Last Post: 2nd May 2007, 14:15

Tags for this Thread

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.