3
votes

I have made an QML application using a frameless window and implemented actions like dragging and resizing by myself. But this way the application doesn't support native window manager features like windows aero snap or the Gnome window manager features. So I searched and found this where someone found a way to support them in a frameless window using the win32 API. But is there a way to use this with a QML application or another way to use the native window manager features?

I initialize the window from C++ with this code:

QQmlApplicationEngine engine(QUrl("qrc:/qml/main.qml"));
QObject *topLevel = engine.rootObjects().value(0);
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);

window->setFlags(window->flags() | Qt::FramelessWindowHint);

if ( !window ) {
    qWarning("Error: Your root item has to be a Window.");
    return -1;
}
window->show();

EDIT: I would also like to use the native window manager drop shadow like in the example I have linked to, if possible.

EDIT: I have a second problem: Following @Kuba Obers instructions I got it to work how it was intended to. But now I have the problem, that when I resize or move it Qt leaves an undrawn area with the size of the frame.

1
did you fixed the problem? it appears to be the same bug I've reported here: bugreports.qt-project.org/browse/…Stefano
I found a dirty workaround by setting the frameless window hint first and then overwriting the window flags with setwindowlong. Additionaly I had to block Qt from handeling the maximize event.user2282732

1 Answers

1
votes

The winapi window handle is provided by window->winId():

HWND handle = window->winId();

You can pass this handle to native functions.

To filter the WM_NCCALCSIZE message, you need to implement a native event handler by subclassing QAbstractNativeEventFilter, and install an instance of it on the application by calling qApp->installNativeEventFilter(myFilter).