Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML window minimal size with frame

Tags:

qt

qml

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.

like image 582
Mariya Kiyan Avatar asked Mar 26 '15 10:03

Mariya Kiyan


2 Answers

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);
    }
}
like image 192
folibis Avatar answered Oct 08 '22 17:10

folibis


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.

like image 30
luke_carter Avatar answered Oct 08 '22 17:10

luke_carter