Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make QtQuick2.0 application window not resizable?

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?

like image 231
S.M.Mousavi Avatar asked Nov 29 '22 02:11

S.M.Mousavi


2 Answers

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
}
like image 165
Ayberk Özgür Avatar answered Dec 16 '22 04:12

Ayberk Özgür


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.

like image 25
mozzbozz Avatar answered Dec 16 '22 04:12

mozzbozz