retif
retif

Reputation: 1652

Fixed size for QML Dialog

I want to forbid resizing for the following Dialog window:

Dialog {
    id: aboutDialog
    width: 300
    height: 200
    title: "About"
    standardButtons: StandardButton.Ok

    GridLayout {
        rows: 2
        columns: 2

        Text { text: "Some:"; font.bold: true; }
        Text { text: "text"; }
        Text { text: "and:"; font.bold: true }
        Text { text: "another"; }
    }
}

Why there is no property like resizable: false? Or is there?

And if I add minimumWidth property, then I get the error: Cannot assign to non-existent property "minimumWidth"

How can I achieve my goal?

upd. Filip helped me with his answer, but still, to make this window non-resizable I have to write this:

width: 300
minimumWidth: 300
maximumWidth: 300
height: 200
minimumHeight: 200
maximumHeight: 200

instead of something like: resizable: false. It's just a bit a lot of lines for such a task.

Upvotes: 1

Views: 6500

Answers (1)

Filip Hazubski
Filip Hazubski

Reputation: 1728

You cannot use Dialog object if you need your window not be resizable. Here is a fragment of the docs:

Note: do not attempt to bind the width or height of the dialog to the width or height of its content, because Dialog already tries to size itself to the content. If your goal is to change or eliminate the margins, you must override contentItem. If your goal is simply to show a window (whether modal or not), and your platform supports it, it is simpler to use Window instead.

Window can have minimum and maximum size. Setting the same max and minimal values makes Window not resizable. I guess you will need just to add an OK button to it and you will have what you need.

Upvotes: 4

Related Questions