January 17, 2011

fifth fifth
Lab Rat
57 posts

How to make brackground transparent

 

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.

10 replies

January 17, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

You can try, setting these attributes on the widget:

  1. setAttribute(Qt::WA_NoBackground);
  2. setAttribute(Qt::WA_NoSystemBackground);
  3. setAttribute(Qt::WA_TranslucentBackground);

additionally, you could set setAutoFillbackground(false).

 Signature 

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

January 17, 2011

fifth fifth
Lab Rat
57 posts

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.

Gerolf wrote:
You can try, setting these attributes on the widget:

  1. setAttribute(Qt::WA_NoBackground);
  2. setAttribute(Qt::WA_NoSystemBackground);
  3. setAttribute(Qt::WA_TranslucentBackground);

additionally, you could set setAutoFillbackground(false).

January 17, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

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

 Signature 

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

January 18, 2011

fifth fifth
Lab Rat
57 posts

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

Gerolf wrote:
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….

January 11, 2013

MrNoway MrNoway
Ant Farmer
50 posts

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.

January 13, 2013

b1gsnak3 b1gsnak3
Robot Herder
193 posts

try adding

  1. scroll->verticalScrollBar()->setStyleSheet("border, background and what else you need")

January 13, 2013

MrNoway MrNoway
Ant Farmer
50 posts

maybe it would work, but there is a syntax error

  1. scroll->verticalScrollBar()->setStyleSheet("...")

“pointer-to-incomplete”

January 13, 2013

MrNoway MrNoway
Ant Farmer
50 posts

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

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

January 14, 2013

b1gsnak3 b1gsnak3
Robot Herder
193 posts

You can customize everything in the scrollbar just by using css… try taking a look here [doc.qt.digia.com] and try out different css commands…

January 18, 2013

Vittal Vittal
Lab Rat
19 posts

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;” );
 
  ‹‹ Widget for using with following purposes? (text editor, links)      Connecting a children widget with main widget ››

You must log in to post a reply. Not a member yet? Register here!