[Qt-interest] Applying background image to QMainWindow?

Tony Rietwyk tony.rietwyk at rightsoft.com.au
Mon Dec 28 00:38:47 CET 2009


Hi Mike, 
 
You need to use CSS rules to apply the background only to the class
QMainWindow, or the specific main window widget name - by default you get
the cascading effect that you are seeing.  Try
 
setStyleSheet("QMainWindow { background-image: url(some_bg.png) }");

or 
 
setStyleSheet("#mainWindowObjectName { background-image: url(some_bg.png)
}");

Regards, 
 

-----Original Message-----

Hi all,

I'm using the latest Qt on Mac OS X, and I'm a bit stuck on trying to set an
image as the background for a QMainWindow. What I'm looking for, is to
somehow set such an image as a background of my program's main window, and
also to let all child widgets (specifically containers like QGroupBox) have
transparent backgrounds so the image shows through. I tried setting the main
window's CSS properties like so:

// inside mainwindow.cpp -> class derives from QMainWindow
setStyleSheet("background-image: url(some_bg.png)");

This seems to work, but the problem is that EVERY child widget also tries to
display that background. That is, instead of having one, uniform background
image in the main window, I get several partial ones displayed on each
widget's background. How would I go about achieving the aforementioned
result?

Thanks!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091228/ea255e89/attachment.html 


More information about the Qt-interest-old mailing list