Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-83424

Calling 'winId' affects all further modifications to the attribute 'WA_TranslucentBackground'

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.14.2
    • Widgets: Main Window
    • None
    • Windows 10
    • Windows

    Description

      Calling QWidget::winId() before setting the attibute WA_TranslucentBackground, prevents the window from being transparent. However doing the opposite works as intended.

      This code creates a window with a transparent background:

      TransparentWindow::TransparentWindow()
          : QWidget()
      {
          setAttribute(Qt::WA_TranslucentBackground);    
          qDebug() << "id: " << winId();
      
          qDebug() << "WA_TranslucentBackground: " << testAttribute(Qt::WA_TranslucentBackground);
          
          setWindowFlags(Qt::FramelessWindowHint);
      
          setLayout(new QHBoxLayout(this));
      
          QPushButton* button1 = new QPushButton(this);
          button1->setFixedSize(100, 30);
          layout()->addWidget(button1);
      
          QPushButton* button2 = new QPushButton(this);
          button2->setFixedSize(30, 100);
          layout()->addWidget(button2);
      }
      

      However inverting those two lines makes the background black:

      qDebug() << "id: " << winId();
      setAttribute(Qt::WA_TranslucentBackground);
      

      In all cases the attribute WA_TranslucentBackground is correctly set to true.
       

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            lucb. L B.
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes