6
votes

I want to set minimal size for my QML window. But if I set the minimal width and height inside my main.qml I've got the window that has minimal size bigger than I set & expect. The problem is that the minimal size is applied to the view inside window frame and the window frame and caption size is not taken into account.

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

Is there a way to set application window minimal size taking into account window frame?

I use Qt 5.4.

2

2 Answers

2
votes

as @luke_carter already said, it's possible by calling one of QFrame's function related to its size, for example QFrame::frameGeometry().It gets you window size including frame and titlebar. So all you need is to ajust the QML window size. I think the best way to do that with a singleton 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
votes

Maybe hide the frame using Qt::FramelessWindowHint (or -frameless if using qml viewer)? I'm guessing it's because the frame is part of the windowing system of the OS.

Just found this, may be possible to get the frame size from the target OS.