transparent Widget
-
@Chris-Kawa
Thanks for reply,
As I realized;
It is possible to make a semi transparent widget (parent/child) in Linux but if I want to do the same in Windows I should use Winextras which windows 8 and later versions don't support it.
Doesn't exist any way to make it possible for Windows 8 and 10? -
windows 8 and later versions don't support it
Well it's not that they don't support it. They do and the APIs are exactly the same. It's just that the style has changed and aero windows are no longer transparent.
I'm afraid I don't have good news. The closest thing to that effect in Windows 10 is the new Acrylic Material:
The bad part is that it is available exclusively via XAML brushes, so while trivial to use with C# it might be very difficult or even impossible to make it work with native C++ (yeah, thanks Microsoft...). Combining it with Qt on top of that. Well... good luck ;)The only other alternative I know is to implement the whole thing yourself i.e. take a screenshot from under the window with native API and write your own DirectX shaders to add the glass effect. That would be just a very dirty hack though that would probably break easily. It is a lot of very low level work involving DirectComposition and expected performance is not gonna be too good. Combining it with Qt would also pose quite a challenge.
The sad state of the world is that Microsoft is heavily promoting XAML technology and has actively taken away all the easy ways to add the same effect to native c++ apps.
-
This post is deleted!
-
This post is deleted!
-
I examined many ways,
But I can't make a transparent tabwidget (In Linux) :
-
It's a 3 step process.
-
Make the window widget transparent using attribute
Qt::WA_TranslucentBackground
, which gives you something like in your picture:
-
Make the tab header transparent. You can do that with stylesheet
QTabBar::tab { background: transparent; }
Note that this is stylingQTabBar
, notQTabWidget
.
You can modify the stylesheet to add the borders of the tab back if you like. -
Make the tab content transparent. Note that
QTabWidget
itself doesn't have a background. It's the background of the widget inside it that you need to make transparent. The easiest way to do this is to tell Qt that the paint event takes care of all the painting and it does not need to fill the background with default color i.e. useQt::WA_OpaquePaintEvent
attribute.
So the entire example looks like this:
int main(int argc, char *argv[]) { QApplication a(argc, argv); QWidget* tab_content = new QWidget(); tab_content->setAttribute(Qt::WA_OpaquePaintEvent); //makes the widget transparent QTabWidget* tw = new QTabWidget(); tw->addTab(tab_content, "Example"); tw->setStyleSheet("QTabBar::tab { background: transparent; }"); //makes the header transparent QWidget w; w.setAttribute(Qt::WA_TranslucentBackground); //makes the window transparent w.setLayout(new QVBoxLayout()); w.layout()->addWidget(tw); w.show(); return a.exec(); }
-
-
@Chris-Kawa
Hi Dear Chris Kawa
The method that you mentioned in previous post helped me a lot.
Thanks a lot.
But I tried to make a semi-transparent canvas (of qwtplot) . The canvas inherit from QFrame. I tried many days but I still can't do that.
A black background will appear instead of parent widget behind it.
QwtPlotCanvas Class Reference -
@Chris-Kawa, I tried your code but it does not work on Windows 10 and Qt 5.15.2. Why? Maybe does somebody else know it?
-
@8Observer8 Were you able to resolve this issue? I'm having weird behavior even though i'm following the instructions, so not sure what am I doing wrong?
-
@Chris-Kawa Your code works nicely on my local computer. But the transparent feature is gone after I copy the executable from my machine to another computer. Any thoughts?
same OS: Ubuntu 22.04
same Qt version: 5.15.3 -
@JoeCFD you people may find this helpfull
https://github.com/jordanprog86/QtTransparentWindow.git
-
@Ronel_qtmaster thanks for your post. Your code is not working on Lubuntu with LXQt desktop as well for Qt5/6. Chris Kawa's test code has the same issue.
The following example works
https://doc.qt.io/qt-5/qtwidgets-widgets-shapedclock-example.html