Results 1 to 3 of 3

Thread: Applying a consistent background

  1. #1
    Join Date
    Dec 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Applying a consistent background

    Hey,

    I'm using Qt4 on Mac OS X. I'm trying to set an image as the background for my main window, and also I want that image to show through all the child widgets so it creates a uniform background. Basically, I want for all child widgets in the main window to have transparent backgrounds, so that the main window's background image shows through. I tried the following:

    // called from constructor of my QMainWindow-derived class
    setStyleSheet("background-image: url(some_bg.png)");

    This basically works, however, EVERY child widget attempts to set this image as its own background. That is, instead of having one, uniform background, I get several partial images as each widget uses that image as its own background. Such as a QLabel, which for some reason draws its normally gray background using that same image. How can I achieve the aforementioned results, where the child widgets let the main window background image simply show through?

    Thanks!

  2. #2
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Applying a consistent background

    Remember, style sheets are cascading (the C in CSS) so child controls will get the style applied to a parent. I think something like this may work:
    Qt Code:
    1. *
    2. {
    3. background-color: rgba(255, 255, 255, 10%);
    4. }
    5. {
    6. background-image: url(some_bg.png);
    7. background-color: gray;
    8. }
    To copy to clipboard, switch view to plain text mode 
    We use the * selector to set the background color of all widgets to (almost) transparent white. We then use the QMainWindow selector to set the background image on QMainWindow derived classes only.

  3. #3
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Applying a consistent background

    Try something like:
    Qt Code:
    1. setStyleSheet("#centralWidget {background-image: url(some_bg.png);} #centralWidget * {background: transparent;}");
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 17th July 2010, 22:07
  2. Problem with OpenGL support (transparent background)
    By developer-nsk in forum Qt Programming
    Replies: 0
    Last Post: 2nd November 2009, 20:31
  3. QLCDNumber with transparent background?
    By PolyVox in forum Qt Programming
    Replies: 2
    Last Post: 20th October 2008, 06:34
  4. background colour
    By kw in forum Qt Programming
    Replies: 6
    Last Post: 11th April 2006, 01:44
  5. Replies: 1
    Last Post: 5th April 2006, 17: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.