tags:

views:

1107

answers:

5

I've got the following class:

class SelectDateDialog(QDialog):
    startDate = date.today()
    endDate = date.today()

    def __init__(self, text, isInterval = False):
        QDialog.__init__(self)
        uic.loadUi("resources/SelectDate.ui", self)

Now, the dialog is resizable on Mac OS X 10.5, but it shouldn't be. It has the resize-handle in the lower right corner.

I've already tried the setSizeGripEnabled function, it didn't change anything.

How can I make it not resizable?

+1  A: 

Hiding the resize handle isn't enough to prevent a resize - the user could still use the winodw manager to resize.

You can use setFixedSize() to prevent a resize doing anything but see this QT thread for reasons why you shouldn't do this.

Martin Beckett
The thing is, even hiding the handle doesn't work.
Georg
+1  A: 

The cleanest way to make a window or dialog non-resizable is to set the size constraint of its layout to QLayout.SetFixedSize (or QLayout::SetFixedSize in C++). You only need to do this for the main layout in the window - the one which contains all the other widgets and layouts.

I see that you're using Qt Designer to create the user interface for your dialog. Open the .ui file and select the window, then scroll down in the property editor until you see the Layout section. Set the layoutSizeConstraint property to SetFixedSize.

When you preview the form, the widgets inside the dialog should be arranged correctly, but you won't be able to resize the dialog.

David Boddie
This is what I use.
Max Howell
+1  A: 

For whatever reason, I have always had to do the following (in Qt Designer) to be absolutely sure the window could not be resized:

sizePolicy -> Horizontal Policy = Fixed
sizePolicy -> Vertical Policy = Fixed

minimumSize -> Width = X
minimumSize -> Height = Y

maximumSize -> Width = X
maximumSize -> Height = Y

Note that I chose X and Y to illustrate that minimumSize == maximumSize. When you do this, the resize handle should disappear on its own, though I have seen at least one distribution of Linux leave the handle on. In that particular case, we just hid the handle, since it could not resize the window anyway.

Chris Cameron
+1  A: 

I use the following code to fix the size of a QDialog:

layout()->setSizeConstraint( QLayout::SetFixedSize ) ;
setSizeGripEnabled( false ) ;

The first line enforces the layout size based on the preferred size of the widgets contained within the layout. The second line removes the actual grip.

To reverse this, you would set the default constraint on the layout and re-enable the size grip.

swongu
A: 

if you want a non-resizable QDialog dlg, then set

dlg.setWindowFlags(Qt::MSWindowsFixedSizeDialogHint);

Amal.G