[Qt-interest] setSizePolicy has no effect in subclass of QDialog

Tony Rietwyk tony.rietwyk at rightsoft.com.au
Tue Jun 2 08:33:56 CEST 2009


Hi Stephen, 
 
Unfortunately, the layout system is the worst subsystem of Qt - both in terms of complexity, and vagueness of documentation.  It is extremely powerful, but after 18 months of using it, I still can't predict what it is going to do! 
 
Do you have a layout within the dialog?  In that case, sizePolicy doesn't apply.  To get the dialog to size according to its contents, have a look at QLayout::setSizeConstraint( QLayout::SetFixedSize ).  Though, I suspect this will affect both directions, not just vertically.  
 
Also, I'm not sure when the sizeHint is actually meaningful.  The layout of the contents occurs somewhere between the polish and show events.  This makes it tricky to do any calculations on the sizes!  
 
Hope that helps, 
 
 

I have a subclass of QDialog:

class EditProjectDlg : public QDialog,
                       public Ui::EditProjectDialog
{
    Q_OBJECT
...
}

Prior to displaying this via exec(), I set the size policy:

    setMinimumSize(sizeHint());
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

to prevent it from being resized vertically.

When the dialog is displayed, I can resize it freely both vertically
and horizontally. Can anyone see what I'm doing wrong ?

-- 
Stephen Collyer


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090602/9fd473a9/attachment.html 


More information about the Qt-interest-old mailing list