Results 1 to 3 of 3

Thread: background-image on QLabel does NOT work

  1. #1
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default background-image on QLabel does NOT work

    QLabel#logo {
    color: red;
    background-image: url(folder/logobackground.png);
    background-repeat: repeat-x;
    background-origin: content;
    }

    Ok I have a QLabel with ObjectName as "logo".
    I set the QLabel text to "boooooooooooooo" or some random text.
    Also keeping in mind that minimum size for this QLabel is 400 pixels wide.
    Now In CSS this would print logobackground.png on the QLabel about as many times as it can fit on the X-axis.

    However, after 2 hours of struggling, I find that QLabel does NOT support background-image, and the documentation must have a typo or something.

    I checked if it can find folder/logobackground.png at least 5 times so don't tell me I have wrong paths. I checked to make sure the Object name is there... in fact, the "boooooo" text does indeed become RED. But it seems QLabel does not support background-image attribute.

    And Just to prove to anyone who doubts my competence in being able to get the paths right etc here is a small application for you to try that proves that QLabel does not support background-image:
    Qt Code:
    1. QApplication app(argc, argv);
    2.  
    3. QLabel hello("Hello world!");
    4. hello.setObjectName("lol");
    5. app.setStyleSheet(QString("QLabel#logo { background-image: url(logobackground.png); }"));
    6. hello.resize(500, 80);
    7.  
    8. hello.show();
    To copy to clipboard, switch view to plain text mode 
    Last edited by VireX; 7th June 2007 at 21:48.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: background-image on QLabel does NOT work

    Could this be the problem:
    For QFrame and its subclasses, you must set the QFrame::frameStyle property to QFrame::StyledPanel; otherwise, the background and border attributes will not be respected.
    ?
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    VireX (8th June 2007)

  4. #3
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: background-image on QLabel does NOT work

    Yes I found that after 3 hours of trying several things... Really really dumb of them to do this and not document that properly. It should be written clearly next to QLabel in stylesheet.html

Similar Threads

  1. Dynamically changing QLabel background colour
    By T4ng10r in forum Qt Programming
    Replies: 19
    Last Post: 19th April 2007, 12:47
  2. background image in QTreeView
    By momesana in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2007, 06:25
  3. QLabel background color
    By munna in forum Newbie
    Replies: 3
    Last Post: 1st May 2006, 15:36
  4. Replies: 1
    Last Post: 5th April 2006, 16:44
  5. [QT4.1.1 XP] background image
    By incapacitant in forum Newbie
    Replies: 3
    Last Post: 1st March 2006, 13:02

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.