Important: Please read the Qt Code of Conduct -

Semi-transparent QDialog is not semi-transparent anymore

  • Hi :-)

    Some time ago, I wrote a dialog (for KPhotoAlbum, cf. ) which appears semi-transparent. I implemented it, according to in the following way:


        void paintEvent(QPaintEvent *);


    void AnnotationDialog::ProposedFaceDialog::paintEvent(QPaintEvent *)
        QColor backgroundColor = Qt::white;
        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

  • Lifetime Qt Champion


    Can you check whether it's still the case with a more recent version 5.9.2 is around the corner.

  • Unfortunately, Qt 5.9.2 is not yet available on Gentoo. I'll check it as soon as possible.

  • Lifetime Qt Champion

    Qt 5.9 on windows 10
    alt text

  • Hi @l3u_

    Have you tried adding:

    setAttribute (Qt::WA_TranslucentBackground);

    into the constructor of MyDialog?

    I had similar problems where my dialogs and frames were "sort-of" transparent and this fixed them.

  • Moderators


    I recently made a custom Messagebox with a semitransparent background. I had a slightly different approach:

    //Because the baseclass is a QWidget:
        virtual void paintEvent(QPaintEvent *)Q_DECL_OVERRIDE{
            QStyleOption opt;
            QPainter p(this);
            style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    //Because its a Qt-Designer-Form-Class I use a StyleSheet:

    No problems at all with that.
    Used: Qt 5.9.1

Log in to reply