How to make QtQuick2.0 application window not resizable?
Asked Answered
M

3

5

I have a QtQuick2.0/QtQuick2.1 application with following default codes on main.cpp:

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    QtQuick2ApplicationViewer viewer;
    viewer.setMainQmlFile(QStringLiteral("qml/WikiTransferor2/mainMode3.qml"));
    viewer.showExpanded();
    return app.exec();
}

How can i make this window not resizable?

Manhandle answered 10/9, 2013 at 12:6 Comment(0)
L
3

Like all QWindow : using flags or with setting min and max size with same value

Lucais answered 26/9, 2013 at 18:34 Comment(2)
More informations than you can find in documentation ? qt-project.org/doc/qt-5.1/qtgui/qwindow.htmlLucais
better answer is setting window flags as you mentioned: Qt::WindowFlags flags = Qt::Window; flags |= Qt::MSWindowsFixedSizeDialogHint;Manhandle
P
22

On (at least) KDE the other answers don't work. The following QtQuick solution worked for me:

ApplicationWindow{
    width: ...
    height: ...

    maximumHeight: height
    maximumWidth: width

    minimumHeight: height
    minimumWidth: width
}
Pink answered 26/7, 2016 at 13:23 Comment(0)
M
5

For those coming here from google like me, searching for a QML/QtQuick solution, because they are using the ApplicationWindow Item, I add this answer.

Simply set the maximum height/width to the minimum height/width:

ApplicationWindow {
    visible: true
    maximumHeight: minimumHeight
    maximumWidth: minimumWidth
    [...]
}

Please note that you should not deactivate the window resizing if there are other possibilities (like resizing the content). The users don't like unresizable windows. For instance, in my case, I only locked the height - because I had the possibility to resize some elements in their width: My QML Slider uses as much space as there is available thanks to QtQuick Layouts. However, resizing a few Buttons and a slider in their height would not make sense. TableViews, TextFields etc., however, are predestinated for being resized.

Marte answered 2/10, 2014 at 12:17 Comment(2)
I should mention I'm on Kubuntu 16.04.Evesham
Maybe this behaviour changed with a new Qt version, I don't know, sorry. Thanks for adding your answer!Marte
L
3

Like all QWindow : using flags or with setting min and max size with same value

Lucais answered 26/9, 2013 at 18:34 Comment(2)
More informations than you can find in documentation ? qt-project.org/doc/qt-5.1/qtgui/qwindow.htmlLucais
better answer is setting window flags as you mentioned: Qt::WindowFlags flags = Qt::Window; flags |= Qt::MSWindowsFixedSizeDialogHint;Manhandle

© 2022 - 2024 — McMap. All rights reserved.