Unsolved Custom widget background is not opacity / transparent.
-
I created a CustomWidget class:
CustomWidget.h:#include <QWidget> #include <QPainter> class CustomWidget : public QWidget { Q_OBJECT public: explicit CustomWidget(QWidget *parent = nullptr); void paintEvent(QPaintEvent* event); signals: public slots: };
CustomWidget.cpp:
#include "customwidget.h" CustomWidget::CustomWidget(QWidget *parent) : QWidget(parent) { this->setWindowFlag(Qt::FramelessWindowHint); } void CustomWidget::paintEvent(QPaintEvent* event) { if (this->isActiveWindow()) { QPainter painter(this); painter.setPen(Qt::green); painter.setBrush(QBrush(QColor(69, 232, 32, 100))); painter.drawRect(rect()); } }
When I compile and run this codes on Linux (KDE Neon), I see correct widget with color (color is green = 69, 232, 32) but opacity (alpha = 100) is not working. Here is picture:
How can I create transparent or opacity widgets? Is this a bug?
Also, I can see transparent widgets if I can create opacity / transparent widget but can't use background (I mean I can't intervene objects that behind of the widget. You know that screencast applications records all screen and we can use screen). Can I create widgets like this?
Thanks. -