QML frameless window supporting aero snap - c++

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.

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).

Related

Win32 Child Window Style Not Matching Parent

I am creating a child window for a VST3 plugin and am finding that the style of the child is different to the parent - in fact windows seems to be picking up an older rounded style from somewhere when I am on windows 10 which has the modern square style.
I don't have control over the parent window style. In this scenario an audio workstation hands me a HWND that I use as the parent handle in
window->win32.handle = CreateWindowExW(exStyle,
_GLFW_WNDCLASSNAME,
wideTitle,
style,
xpos, ypos,
fullWidth, fullHeight,
parent_handle,
NULL,
GetModuleHandleW(NULL),
NULL);
I am using (a slightly modified - to accept a parent handle - and freshly compiled) version of GLFW to create the window.
Does anyone have an idea about where the style could be changing?
When I create the window as a parent window the correct style is applied. To create the child I am adding WS_CHILD to this. Digging out the exact style is hard because GLFW constructs it in a sequence of functions.
As a Late Edit. It seems similar to this problem reported with MDI windows
where MDI child window styles don't match the parent style from wayyy back in Win7 - but still is being mentioned.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/34b29567-28a1-4aeb-97d2-d1476ba856f5/mdi-child-window-appearance?forum=vcgeneral

Constraining draggable child windows within parent window?

Please take a look at this screenshot:
As you can see, the "Executable modules" and "Threads" child windows are free to roam about in the sandbox-like "Themida" parent window, and if they get dragged past the edge the overflow simply gets hidden. How can I create this effect?
That is a Multiple Document Interface (MDI) application. The containing window, with the dark grey background is the MDI client window, and the windows inside are the MDI child windows.
The use of MDI has been discouraged by Microsoft for many years so you may wish to think twice about using it in a new application.
Simply set the window style to WS_CHILD, and the window will be confined in the parent client rectangle.
You can do this during window creation, or after using SetWindowLongPtr() and GetWindowLongPtr():
SetWindowLongPtr(hwnd, GWL_STYLE, WS_CHILD | GetWindowLongPtr(hwnd, GWL_STYLE));
P.S. You don't need to create an MDI application to have this behavior.

QT: Frameless window not animating

i need some help for my current project named "RibbonUI".
As the project name suggest, i want to implement the MS RibbonUI like in Office 2013 in QT - most stuff is working nice but i need to know something about the Qt::FramelessWindowHint.
I have subclassed the QMainWindow and added the enum value Qt::FramelessWindowHint to override the default window decoration. The buttons are implemented fine - i can minimize, maximize and close my frameless window, but the window is not animated when minimizing/maximizing/restore the window from the taskbar.
Do i have to implement the animation by myself or can i use a window manager hint or something else?
Here is a screenshot from my current work:

Force QWidget Child to have its own Window Handle

I am trying to create a small application using Qt. What I want to do is to display in a dock widget a 3D Interface using DirectX11, other widgets in the QMainWindow will have properties to modify the behavior of what is been displayed in DX11.
The problem I am facing is that when I add a QDockWidget to QMainWindow, the dockWidgetContents function windowHandle returns NULL.
I am using an example from Get HWND on windows with Qt5 (from WId) to get the HWND. But if the function return NULL it will go up and get the HWND of the QMainWindow.
Is there any way to force a QWidget to have its own window handle?
Thanks for any advice!
Yes. You have several options for that. See the topic Native Widgets vs Alien Widgets in the QWidget class documentation.
Use the QT_USE_NATIVE_WINDOWS=1 in your environment.
Set the Qt::AA_NativeWindows attribute on your application. All widgets will be native widgets.
Set the Qt::WA_NativeWindow attribute on widgets: The widget itself and all of its ancestors will become native (unless Qt::WA_DontCreateNativeAncestors is set).
Call QWidget::winId to enforce a native window (this implies 3).
Set the Qt::WA_PaintOnScreen attribute to enforce a native window (this implies 3).

Transparent window in Qt

How can I create a transparent window in Qt for Linux. I tried the following, but it doesn't work:
myWidget::myWidget(QWidget *parent) : QWidget(parent, Qt::FramelessWindowHint) {
setWindowOpacity(0.4);
}
"Note that under X11 you need to have
a composite manager running, and the
X11 specific _NET_WM_WINDOW_OPACITY
atom needs to be supported by the
window manager you are using."
https://doc.qt.io/qt-5/qwidget.html#windowOpacity-prop
What window manager are you using?
http://en.wikipedia.org/wiki/Compositing_window_manager#List_of_compositing_window_managers
Does your server support the "Composite extension"?
http://en.wikipedia.org/wiki/Composite_(graphics)
Does your card support it?
Try to use QGraphicsOpacityEffect and QWidget::setGraphicsEffect
I had a similar issue but on windows, not sure if it will help in Linux
Instead of Qt::FramelessWindowHint use Qt::SplashScreen. I can have a frameless and transparent window on top of my other widgets.