Minimum QML window size with border

I want to set a minimum size for my QML window. But if I set the minimum width and height inside my main.qml, I have a window with a minimum size larger than what I installed and expected. The problem is that the minimum size is applied to the view inside the window frame, and the window size and title size are not taken into account.

ApplicationWindow { id: application minimumWidth: 1024 minimumHeight: 768 visibility: "Maximized" } 

Is there a way to set the minimum size of the application window based on the window frame?

I am using Qt 5.4.

+5
source share
2 answers

As @luke_carter already said, this is possible by calling one of the QFrame functions associated with its size, for example QFrame :: frameGeometry () . It gets the size of the window , including the title. So all you need is to resize the QML window. I think the best way to do this is with a singlet with suitable functions, for example:

 QRect MySingleton::frameSize(QObject *window) { QQuickWindow *qw = qobject_cast<QQuickWindow *>(window); if(qw) return qw->frameGeometry(); return QRect(); } 

In QML:

 Window { id: wnd visible: true width: 300 height: 300 Component.onCompleted: { var rect = MySingleton.frameSize(wnd); console.log(rect.width + "," + rect.height); } } 
+2
source

Maybe hide a frame using Qt::FramelessWindowHint (or -frameless when using the qml viewer)? I guess this is because the frame is part of the OS window system.

This just found, it is possible to get the frame size from the target OS.

+2
source

Source: https://habr.com/ru/post/1216173/


All Articles