View Full Version : Setting background image of QFrame

12th February 2007, 20:17
Hello! I'm having some trouble getting a background image to show up in a QFrame using Qt 4.2.2. Here is a snippit of the code that I have:

ui.frame->setStyleSheet("background-image: url(:/images/menu_background.png);"
"background-repeat: repeat;");

The image being referenced is pulled in via a QRC file I have in the project. However, for some reason the image isn't showing up... Is there something I'm doing wrong?

Here's the contents of the QRC file for reference:

<qresource prefix="/" >


- Clay

12th February 2007, 20:21
Have you noticed the note (http://doc.trolltech.com/4.2/stylesheet.html#list-of-attributes):

For QFrame and its subclasses, you must set the QFrame::frameStyle property to QFrame::StyledPanel; otherwise, the background attribute will not be respected.

12th February 2007, 20:50
Ah, you're very right - I missed seeing that comment when I was skimming through the documentation (need to work on my reading comprehension... *sigh*).

Originally I had the QFrame::frameShape set to QFrame::NoFrame and the QFrame::frameShadow set to QFrame::Plain. When I changed it back to QFrame::StyledPanel I also had to change the QFrame::frameShadow to QFrame::Raised in order for the background image to show up properly.