Changing the drop drop shadow of a QMenu
-
Hey guys.
How do I change the drop shadow of a QMenu? Using
setGraphicsEffect()
with aQGraphicsDropShadowEffect
does not work. Im using QTWidgets with C++.
The default shadow is pretty bad and only at the bottom and right corner.Thanks.
-
Maybe you have to set Qt::NoDropShadowWindowHint window flag for your QMenu.
[edit] shadow effet only works inside the widget, look at my example here:
https://forum.qt.io/post/688750 -
This only removes the default drop shadow.
// EDIT:
What do you mean with "inside the widget"? -
This only removes the default drop shadow.
// EDIT:
What do you mean with "inside the widget"?@VogelPapaFinn
Shadows can't be drawn outside the top level widget frame.
In your case QMenu. -
@VogelPapaFinn
Shadows can't be drawn outside the top level widget frame.
In your case QMenu.@mpergand dafuq. Then how does it create the default shadow??
-
A menu is a window. Windows have a client and non-client area. Client area is everything inside the frame. That's where the application does its own painting, either through Qt or other means. QGraphicsEffect is just a helper that lets you draw stuff, but it is limited to the client area.
The non-client area is the frame and everything outside of it (e.g. the shadow). That part is painted by the OS and its window manager, which are platform specific and can vary widely between OS versions or window managers. Some may draw shadows, some may draw colored borders, some may have none of it. It's mostly out of control of the app what the style of that area is. Some window managers expose some customization points, like that
NoDropShadowWindowHint
that @mpergand mentioned, but that's why it has "hint" in the name - it's a suggestion to the OS and it's up to it to honor it or not. There's no direct control over how the window manager draws window frames or what effects it adds to it. It will look differently on different systems. -
A menu is a window. Windows have a client and non-client area. Client area is everything inside the frame. That's where the application does its own painting, either through Qt or other means. QGraphicsEffect is just a helper that lets you draw stuff, but it is limited to the client area.
The non-client area is the frame and everything outside of it (e.g. the shadow). That part is painted by the OS and its window manager, which are platform specific and can vary widely between OS versions or window managers. Some may draw shadows, some may draw colored borders, some may have none of it. It's mostly out of control of the app what the style of that area is. Some window managers expose some customization points, like that
NoDropShadowWindowHint
that @mpergand mentioned, but that's why it has "hint" in the name - it's a suggestion to the OS and it's up to it to honor it or not. There's no direct control over how the window manager draws window frames or what effects it adds to it. It will look differently on different systems.@Chris-Kawa so there is no chance of using a good shadow? Oh man that shit sucks.
-
@Chris-Kawa so there is no chance of using a good shadow? Oh man that shit sucks.
@VogelPapaFinn You can try to override the non-client area painting if your particular platform lets you. You would override nativeEvent() and look for the platform specific message to implement the painting. For example on Windows that's the WM_NCPAINT message.
But this is highly platform and window manager specific. You're on your own there. Qt can't help you with this, so no QPainter, QGraphicsEffect or anything like that. Only native APIs.