Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, August 2006
[QT4] Preventing a QDialog from being resized


Message 1 in thread

Hi,

>From several threads I can find on this list, it seems that preventing a
QDialog from being resized is a real challenge. In fact, I didn't find a
working solution. It is noteworthy that most of the solutions I can find
came from the pre-Qt4 era and can't be transposed as is. So I was
wondering what's wrong with the following code snippet:

QDialog dialog;
dialog.setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );

Indeed, the created dialog can be resized without a problem, whereas I
think it shouldn't. I use many other built-in Qt widgets in my code and
setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) works as
expected on them.

Is this setSizePolicy() particular behaviour a feature of the QDialog
class or am I missing something trivial here?

Cheers,

	Ãmeric

--
 [ signature omitted ] 

Message 2 in thread

On 18.08.06 16:32:39, Émeric Maschino wrote:
> QDialog dialog;
> dialog.setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
> 
> Indeed, the created dialog can be resized without a problem, whereas I
> think it shouldn't. I use many other built-in Qt widgets in my code and
> setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) works as
> expected on them.
> 
> Is this setSizePolicy() particular behaviour a feature of the QDialog
> class or am I missing something trivial here?

I guess so, however setting sizeGripEnabled to false on the dialog
should make it fixed size. This property is also available on Qt3 so I'm
not sure wether it really is that hard to make a fixed size QDialog.
However I've not tried to use this yet.

Andreas

-- 
 [ signature omitted ] 

Message 3 in thread

> I guess so, however setting sizeGripEnabled to false on the dialog
> should make it fixed size. This property is also available on Qt3 so
> I'm
> not sure wether it really is that hard to make a fixed size QDialog.
> However I've not tried to use this yet.

sizeGripEnabled() doesn't exist anymore in QT4. Furthermore, as was
emphasized in an other thread, hiding the size grip doesn't prevent a
user from resizing a QDialog by grabing its borders. So, a proposed
solution was to remove the borders thanks to Qt::WStyle_NoBorder. With
QT4, this has been deprecated by Qt::FramelessWindowHint. But such a
QDialog has no WM decoration at all and can't be moved for example.

	Ãmeric

--
 [ signature omitted ] 

Message 4 in thread

On 18.08.06 17:01:26, Émeric Maschino wrote:
> > I guess so, however setting sizeGripEnabled to false on the dialog
> > should make it fixed size. This property is also available on Qt3 so
> > I'm
> > not sure wether it really is that hard to make a fixed size QDialog.
> > However I've not tried to use this yet.
> 
> sizeGripEnabled() doesn't exist anymore in QT4.

No, not really, the method name changed due to a changed naming-style,
but it is still there. See http://doc.trolltech.com/4.1/qdialog.html#sizeGripEnabled-prop

> Furthermore, as was
> emphasized in an other thread, hiding the size grip doesn't prevent a
> user from resizing a QDialog by grabing its borders.

As I said, I didn't test it, but yes the documentation says nothing
about preventing the size-change.

> So, a proposed solution was to remove the borders thanks to
> Qt::WStyle_NoBorder. With QT4, this has been deprecated by
> Qt::FramelessWindowHint. But such a QDialog has no WM decoration at
> all and can't be moved for example.

The reason for this "feature" not existing might well be that a
non-resizable dialog is something you shouldn't need to use. For
example, if the user chooses to use a large font, he won't see the whole
dialog (well, there are ways around this). Also I don't think people
resize dialogs that much as long as they can see everything necesarry.

On the other hand you could try to combine FramelessWindowHint with
WindowTitleHint, WindowMinimizeButtonHint and so on.

Andreas

-- 
 [ signature omitted ] 

Message 5 in thread

> The reason for this "feature" not existing might well be that a
> non-resizable dialog is something you shouldn't need to use. For
> example, if the user chooses to use a large font, he won't see the whole
> dialog (well, there are ways around this). Also I don't think people
> resize dialogs that much as long as they can see everything necesarry.

I finally managed to have a working resizeable dialog. However, since
QColorDialog isn't resizeable IIRC, there's probably a manner to do
this. In a private mail, I was told that setting the minimumSizeHint()
and maximumSizeHint() do the trick.

	Ãmeric

--
 [ signature omitted ] 

Message 6 in thread

Am Freitag, 18. August 2006 16:32 schrieb Ãmeric Maschino:
[...]
> Is this setSizePolicy() particular behaviour a feature of the QDialog
> class or am I missing something trivial here?

You are.  The idea with sizePolicy for toplevel windows is a good one, though. 
We might run into technical limitations, some old window systems or window 
managers don't like changing a fixed size if e.g. the size hint changes. 
Anyway,  I'll make a task.

Until then, the following properties always existed in Qt:

http://doc.trolltech.com/4.1/qwidget.html#setFixedSize

Set the fixed size to sizeHint().

Or on Windows, you properly want to set the Qt::MSWindowsFixedSizeDialogHint

http://doc.trolltech.com/4.1/qt.html#WindowType-enum

Last but not least: don't. Why not simply use QLayout and let the user resize 
the dialog if they want to.

Matthias

--
 [ signature omitted ]