Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Semi-transparent QDialog is not semi-transparent anymore
Qt 6.11 is out! See what's new in the release blog

Semi-transparent QDialog is not semi-transparent anymore

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 3.5k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • l3u_L Offline
    l3u_L Offline
    l3u_
    wrote on last edited by
    #1

    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

    J.HilkJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • l3u_L Offline
        l3u_L Offline
        l3u_
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          Qt 5.9 on windows 10
          alt text

          1 Reply Last reply
          0
          • BuckwheatB Offline
            BuckwheatB Offline
            Buckwheat
            wrote on last edited by
            #5

            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.

            Dave Fileccia

            1 Reply Last reply
            0
            • l3u_L l3u_

              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

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by J.Hilk
              #6

              @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


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved