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. Cannot make transparent (translucent) background using Qt styles
Forum Updated to NodeBB v4.3 + New Features

Cannot make transparent (translucent) background using Qt styles

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 3.2k Views 2 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.
  • S Offline
    S Offline
    sonulohani
    wrote on last edited by sonulohani
    #1

    I have used the Qt widgets->styles example to test this functionality.

    The only change i have made is that in the method

    void NorwegianWoodStyle::polish(QWidget *widget)
    

    I have added two lines of code:-

    if(widget->isWindow())
    { 
    widget->setWindowFlags( Qt::FramelessWindowHint ); 
    widget->setAttribute( Qt::WA_TranslucentBackground ); 
    }
    

    However the output is not what i am expecting. Its showing output with black background in QT 5.7. However when building the same example with Qt 4.8 I am able to see the transparent background. The following screenshots in the attachment section will help you more in understanding the problem.

    Qt 4.8
    Qt 5.7

    Could you please tell me if this is Qt bug and is there any alternative resolution to this problem.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! You need to put your extra code in the dialog's constructor:

      WidgetGallery::WidgetGallery(QWidget *parent)
          : QDialog(parent)
      {
          setWindowFlags( Qt::FramelessWindowHint );
          setAttribute( Qt::WA_TranslucentBackground );
          //...
      

      Wouldn't call it a bug, just different behaviour between major Qt versions.

      1 Reply Last reply
      2
      • S Offline
        S Offline
        sonulohani
        wrote on last edited by sonulohani
        #3

        Thanks for the reply. But what i am trying to do is to switch the style from opaque background to transparent and vice versa via user input. So when i launch my application it should be opaque and when user selects transparent mode i repolish again the application to show transparent. At first while launching the application the transparency is working fine but thats before calling show method. However if i do the same using styles its not working. I tried using pallete as well and set it to widget background role however i am still getting the black background. I tried debugging the Qt code as well and what i saw is that when we set WA_TransulentBackground to widget before show its executing the create_sys() method and in that we set the QSurfaceFormat alphabuffersize to 8 and its working fine. However if we set the same attribute after the show function its executing updateIsTranslucent function and there its unable to set the alphabuffersize and because of that i am getting black background. Correct me if i am wrong however i think this is more or less seems to me as a Qt bug. Note that i need opaque background first and transparent later based on user input.

        Thank you

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          i need opaque background first and transparent later

          Didn't know that's supported. So you might be right calling it a bug. Maybe you want to check the bug database or ask the developers on the mailing list.

          S 1 Reply Last reply
          0
          • ? A Former User

            i need opaque background first and transparent later

            Didn't know that's supported. So you might be right calling it a bug. Maybe you want to check the bug database or ask the developers on the mailing list.

            S Offline
            S Offline
            sonulohani
            wrote on last edited by
            #5

            @Wieland Thanks for the quick reply. Now let me tell you one more thing. I have an application which works like this with Qt 4.6.2 and i have tried the same in Qt 4.8.4 and it works perfectly fine and switching from opaque to transparent worked as expected. However when i ported my application to Qt 5. 6.2 as its an LTS release i found this strange behaviour (black background on switching to transparent) and made me wonder why such a weird output. What i mean to say here is that it used to give switching of background functionality. So i hope this should work in the latest version as well.

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              This is QTBUG-57531.

              S 1 Reply Last reply
              0
              • ? A Former User

                This is QTBUG-57531.

                S Offline
                S Offline
                sonulohani
                wrote on last edited by
                #7

                @Wieland Okay. Thank You

                1 Reply Last reply
                0

                • Login

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