Results 1 to 7 of 7

Thread: QListWidget transparent background or pixmap

  1. #1
    Join Date
    Mar 2009
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QListWidget transparent background or pixmap

    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

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget transparent background or pixmap

    Did you try changing the opacity of listwidget ? or setting background as transparent ?

  3. #3
    Join Date
    Mar 2009
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget transparent background or pixmap

    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.
    Last edited by wdezell; 4th March 2009 at 19:26. Reason: updated contents

  4. #4
    Join Date
    Mar 2009
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: QListWidget transparent background or pixmap FIXED

    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.

  5. #5
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QListWidget transparent background or pixmap FIXED

    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 "#"

  6. #6
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget transparent background or pixmap

    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

  7. #7
    Join Date
    Mar 2009
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget transparent background or pixmap

    Qt Code:
    1. qDebug () << "Will do. It's a lot easier than what I was doing. Thanks.";
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QWizard::Background Pixmap
    By divya balachandran in forum Installation and Deployment
    Replies: 9
    Last Post: 10th January 2009, 14:40
  2. QLCDNumber with transparent background?
    By PolyVox in forum Qt Programming
    Replies: 2
    Last Post: 20th October 2008, 05:34
  3. Transparent Pixmap
    By maverick_pol in forum Qt Programming
    Replies: 6
    Last Post: 19th December 2007, 16:25
  4. Replies: 3
    Last Post: 8th December 2006, 18:51
  5. Replies: 1
    Last Post: 5th April 2006, 16:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.