Results 1 to 7 of 7

Thread: Two widgets in a QLayout

  1. #1
    Join Date
    Feb 2009
    Posts
    20

    Default Two widgets in a QLayout

    Hello,

    I have two widgets, which I want to insert in a QVBoxLayout.
    The first widget is much smaller, then the second one.
    But unfortunately, the two widgets using exact the same size, it's the perfect half size of the Layout.

    How can I change this behaviour?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Two widgets in a QLayout

    QBoxLayout::addWidget ( QWidget * widget, int stretch = 0, Qt::Alignment alignment = 0 )
    Use the second parameter or alter the QSizePolicy of the widgets.

  3. #3
    Join Date
    Feb 2009
    Posts
    20

    Default Re: Two widgets in a QLayout

    I thought about changing the sizepolicy in the smaller widget, but I got strange results.

    e.g.
    Qt Code:
    1. this->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Two widgets in a QLayout

    In your case it should be the best using the stretch parameter. Have you tried that?

  5. #5
    Join Date
    Feb 2009
    Posts
    20

    Default Re: Two widgets in a QLayout

    yes, this works, but I find this is some kind of manually. I would find it better if the layout is automatically resized to the size of the smaller widget.

    e.g. when I inser directly a QComboBox, then the layout for the box is only as big as the box.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: Two widgets in a QLayout

    What is the size policy of the bigger widget? If you set it to preferred/preferred or maximum/maximum and the smaller widget to minimum or fixed then the layout should adjust. Note it will not work if the parent of the two widgets is a top-level window. Then you'll need to set a constraint on the window's layout.
    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.


  7. #7
    Join Date
    Dec 2012
    Posts
    45
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Two widgets in a QLayout

    hii everyone i am new to Qt and want to implment Analog and digital clock in same ui can any one tell me how to do this ??

Similar Threads

  1. Qt3 - Multiple transparent widgets
    By bythesea in forum Qt Programming
    Replies: 4
    Last Post: 11th September 2009, 11:24
  2. Mac OS X Top-Level Transparent Widgets
    By tinsuke in forum Qt Programming
    Replies: 0
    Last Post: 17th October 2008, 16:01
  3. Upper limit on number of widgets?
    By jdiewald in forum Qt Programming
    Replies: 1
    Last Post: 29th September 2008, 23:00
  4. Replies: 2
    Last Post: 16th May 2008, 14:39
  5. widgets behind hidden widgets not working
    By bpetty in forum Newbie
    Replies: 13
    Last Post: 7th September 2007, 20:23

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.