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. How to make brackground transparent

How to make brackground transparent

Scheduled Pinned Locked Moved General and Desktop
12 Posts 6 Posters 12.8k Views 1 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.
  • F Offline
    F Offline
    fifth
    wrote on last edited by
    #1

    I've built a custom QScrollArea-based widget, but it's default background was some color. I'd like to make background transparent so that it could display widgets which were even under it if overlapped.
    However I didn't see there's a transparent role in setBackgroundRole(), then how could I do?

    thx.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      You can try, setting these attributes on the widget:

      setAttribute(Qt::WA_NoBackground);

      setAttribute(Qt::WA_NoSystemBackground);

      setAttribute(Qt::WA_TranslucentBackground);

      additionally, you could set setAutoFillbackground(false).

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fifth
        wrote on last edited by
        #3

        setAutoFillBackground didn't simply work.
        WA_NoBackground was obsolete and the successor WA_OpaquePaintEvent said in opposite way, and didn't work either.
        WA_NoSystemBackground and WA_TranslucentBackground ended up with a little bit repainting issue, since it never automatically updated newly exposed area, for instance. Then the tough part would turn to that I have to paint everything underneath the widget.

        If memory severed me, QFrame is by default transparent, don't know how it get that.

        [quote author="Gerolf" date="1295255973"]You can try, setting these attributes on the widget:

        setAttribute(Qt::WA_NoBackground);

        setAttribute(Qt::WA_NoSystemBackground);

        setAttribute(Qt::WA_TranslucentBackground);

        additionally, you could set setAutoFillbackground(false).[/quote]

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          I hope you know that a QScrollArea consists of two widgets?
          it has the scroll area itself and the viewport widget. Both must be transparent....

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fifth
            wrote on last edited by
            #5

            I was aware of that. I set those attribute on both widget.

            [quote author="Gerolf" date="1295265476"]I hope you know that a QScrollArea consists of two widgets?
            it has the scroll area itself and the viewport widget. Both must be transparent....[/quote]

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MrNoway
              wrote on last edited by
              #6

              its little bit old, but the problem seems to be still up to date.

              if you use

              scroll->setStyleSheet("background-color:transparent;");

              its working pretty good, but the "Scroll Bar" is getting transparent too,
              making it pretty hard to scroll.

              if someone knows how to fix it, please post.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                b1gsnak3
                wrote on last edited by
                #7

                try adding
                @scroll->verticalScrollBar()->setStyleSheet("border, background and what else you need")@

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  MrNoway
                  wrote on last edited by
                  #8

                  maybe it would work, but there is a syntax error
                  @scroll->verticalScrollBar()->setStyleSheet("...")@

                  "pointer-to-incomplete"

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    MrNoway
                    wrote on last edited by
                    #9

                    my fault, I didnt
                    #include <qscrollbar.h>

                    @scroll_gunshop->verticalScrollBar()->setStyleSheet("background-color:red");@

                    but there is still a little "pattern" in there.
                    the part where the scroll bar is not covered.

                    http://img534.imageshack.us/img534/2594/ddddiw.jpg

                    but looks almost perfect.

                    thanks*

                    € or maybe this is just the normal "natural" scroll bar pattern
                    if you use white it's gone.

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      b1gsnak3
                      wrote on last edited by
                      #10

                      You can customize everything in the scrollbar just by using css... try taking a look "here":http://doc.qt.digia.com/qt/stylesheet-examples.html#customizing-qscrollbar and try out different css commands...

                      1 Reply Last reply
                      0
                      • V Offline
                        V Offline
                        vittalonline
                        wrote on last edited by
                        #11

                        hope this will be helpful to you

                        setAttribute(Qt::WA_TranslucentBackground);
                        
                        setAttribute(Qt::WA_NoSystemBackground,false);
                        
                        setWindowFlags(Qt::FramelessWindowHint);
                        
                        setStyleSheet("font-weight:bold;color:white;"
                                      "background-color: rgba(0,0,0,80%);"
                                      "font: bold 20px;"
                                      "font-weight:bold;"
                                      );
                        
                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          pal_vic
                          wrote on last edited by
                          #12

                          QPalette pal;
                          pal.setColor(QPalette::Window,QColor(0,0,0,0));
                          z_scroll->setPalette(pal);
                          z_scroll->setBackgroundRole(QPalette::Window);
                          z_scroll->widget()->setPalette(pal);
                          z_scroll->widget()->setBackgroundRole(QPalette::Window);

                          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