PDA

View Full Version : QListWidget transparent background or pixmap



wdezell
3rd March 2009, 22:49
I've got a requirement to display several tabs of icons on a nice textured background. My initial approach is a QTabWidget with a QFrame on each pane. The frame backgrounds are set as follows and are working fine:

QPalette p;
p.setBrush ( this->backgroundRole ( ), QBrush ( QImage ( ":/themes/themes/dark/mw_background.png" ) ) );
frameTab0->setPalette ( p );
frameTab1->setPalette ( p );

Next, I've placed a QListWidget into each of the frames (Icon View Mode, AutoFillBackground = true). I would like to see the QFrame texture through the QListWidget (everywhere there is no icon, like in Konqueror with a background texture active). For the life of me I can't achieve my goal.

I have tried this code thinking QListWidget might inherit its parent's background:

listWidgetTab0->setBackgroundRole ( QPalette::NoRole );

I have also dispensed with the QFrame (placing QListWidget directly onto the QTabWidget panes) and tried to apply the texture directly as follows:

QPalette p;
p.setBrush ( this->backgroundRole ( ), QBrush ( QImage ( ":/themes/themes/dark/mw_background.png" ) ) );
listWidgetTab0->setPalette ( p );
listWidgetTab1->setPalette ( p );

QListWidget background remains a solid color rather than taking the pixmap as QFrame. Any suggestions as to what I'm doing wrong? Advice appreciated.

Platform is Qt 4.3.3 X11.


Bill:confused:

aamer4yu
4th March 2009, 05:54
Did you try changing the opacity of listwidget ? or setting background as transparent ?

wdezell
4th March 2009, 16:01
I did try forcing transparency on the QListWidget as follows:

QPalette p;
p.setBrush ( QPalette::Window, Qt::transparent );
listWidgetTab0->setPalette ( p );


but noticed no change. Likewise, listWidgetTab0->setWindowOpacity ( 0.0 ) does nothing for me (and I have a compositing X server).

I haven't tried changing QListWidget with style sheets because I want to localize the styling to just a few widgets. Is there a certain magic combination of frameShape/frameShadow attributes required to make this work as there is with stylesheets? I've tried various combinations with no luck (right now using QFrame::StyledPanel/QFrame::Raised).

I am obviously missing something here. I have tested my code under both Qt 4.3.3 X11 (Kubuntu 8.04) and Qt 4.3.3/MinGW under Win XP and behavior is the same.

Suggestions appreciated.

wdezell
6th March 2009, 17:53
The following code squence achieves the result I wanted:


QPalette p = listWidgetTab0->palette ( );
p.setBrush ( QPalette::Base, QBrush ( QImage ( ":/themes/themes/dark/mw_background.png" ) ) );
listWidgetTab0->setPalette ( p );

As I was trying to alter the widget background I thought QPalette::Background or the now-recommended QPalette::Window was the logical parameter. Not so -- QPalette::Base did the trick.

JimDaniel
6th March 2009, 18:10
Thanks for posting your solution. For future reference, when posting code, use the code tag in the post editor. There is a menu item to insert it, the one that looks like "#"

talk2amulya
6th March 2009, 18:25
i think wdezell will soon recieve a warning from jpn or some other moderator to include code in code tags ... i'm sure we've all been there :D

wdezell
6th March 2009, 18:53
qDebug () << "Will do. It's a lot easier than what I was doing. Thanks.";