Semi-transparent QDialog is not semi-transparent anymore
-
Hi :-)
Some time ago, I wrote a dialog (for KPhotoAlbum, cf. https://cgit.kde.org/kphotoalbum.git/tree/AnnotationDialog/ProposedFaceDialog.cpp ) which appears semi-transparent. I implemented it, according to https://wiki.qt.io/QWidget_Semi-transparent_Background_Color in the following way:
.h:
protected: void paintEvent(QPaintEvent *);
.cpp:
void AnnotationDialog::ProposedFaceDialog::paintEvent(QPaintEvent *) { QColor backgroundColor = Qt::white; backgroundColor.setAlpha(160); QPainter painter(this); painter.fillRect(rect(), backgroundColor); }
which worked just fine. I however noticed today that this is not the case anymore: the widget appears grey and opaque. I'm not sure when this happened, but it's definitely the case with Qt 5.7.1.
I would greatly appreciate all help on how to fix this!
Cheers, Tobias
-
Hi,
Can you check whether it's still the case with a more recent version 5.9.2 is around the corner.
-
Hi
Qt 5.9 on windows 10
-
I recently made a custom Messagebox with a semitransparent background. I had a slightly different approach:
//Because the baseclass is a QWidget: protected: virtual void paintEvent(QPaintEvent *)Q_DECL_OVERRIDE{ QStyleOption opt; opt.init(this); QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } //Because its a Qt-Designer-Form-Class I use a StyleSheet: this->setObjectName("myMessage"); this->setStyleSheet("QWidget#myMessage{background-color:rgba(94,122,135,220);}");
No problems at all with that.
Used: Qt 5.9.1