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


  • Lifetime Qt Champion

    Hi,

    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.


  • Qt Champions 2016

    Hi
    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.



  • @l3u_

    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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.