Results 1 to 5 of 5

Thread: How to keep widget's size to one which is just sufficiennt to display contents?

  1. #1
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Arrow How to keep widget's size to one which is just sufficiennt to display contents?

    Hi

    Here is the constructor for main widget:
    Qt Code:
    1. GMessenger::GMessenger() : QWidget(0, Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint){
    2. setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
    3. m_pLayout = new QVBoxLayout();
    4. setLayout(m_pLayout);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Here is the constructor for child widget:
    Qt Code:
    1. GMessenger::ProgressJobNotifier::ProgressJobNotifier(const QString &title) : QFrame(0){
    2. setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
    3. setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
    4.  
    5. ...
    6.  
    7. setLayout(m_pVLayout);
    8. }
    To copy to clipboard, switch view to plain text mode 


    QFrame derived child widget increases/decreases its size when a child widget is added to it, while QWidget derived top level widget increases its size when a child widget is added but not decreases its size when a child widget is removed (Which is what i want). So help please!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to keep widget's size to one which is just sufficiennt to display contents?

    Quote Originally Posted by yogeshm02 View Post
    QWidget derived top level widget increases its size when a child widget is added but not decreases its size when a child widget is removed (Which is what i want).
    Are you sure? Judging from the title of your post, you want the opposite.

    QWidget::adjustSize()

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

    Default Re: How to keep widget's size to one which is just sufficiennt to display contents?


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

    yogeshm02 (10th December 2006)

  5. #4
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Lightbulb Re: How to keep widget's size to one which is just sufficiennt to display contents?

    QLayout::setSizeConstraint(QLayout::SetFixedSize) is working
    But, it seems like I'll have to invest more time understanding behaviour of QLayout::setSizeConstraint(QLayout::SetFixedSize) and setSizePolicy(QSizePolicy::Policy, QSizePolicy::Policy)

    Bye

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

    Default Re: How to keep widget's size to one which is just sufficiennt to display contents?

    The difference is simple - sizepolicy constrains the size of a widget when that widget is in a layout (so it doesn't work for top level widgets) and setSizeConstraint controls the parent of the layout (or rather the layout itself).

Similar Threads

  1. QLogText & QLogTable : 2 widgets to display text log
    By fcoiffie in forum Qt-based Software
    Replies: 7
    Last Post: 28th April 2019, 08:52
  2. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 23:14

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.