PDA

View Full Version : how to change background of mainwindow with image



babu198649
2nd March 2008, 13:55
hi
how to make a image as a background for mainwindow.

jpn
2nd March 2008, 14:10
Qt Style Sheets (http://doc.trolltech.com/4.3/stylesheet.html)

WinchellChung
3rd March 2008, 21:08
And an extra question:

My main screen is a QWidget. I can set the background image with a style sheet containing the following:



QWidget#myMainWindow
{
background-image: url(../data/my_background.png);
}


The trouble is that my main window has a geometry of 0,0,1024,768, which matches the dimensions of the background image. However, if the user re-sizes the window to larger than that, the background image tiles to fill the background. This is visually ugly.

What I want is for the background image to automatically scale itself, like a QLabel with the ScaledContents flag set to True.

So far I have failed to find any way of doing this. I even tried making a huge QLabel in the background, but could not force Qt Designer to place buttons and things on top of the QLabel.

Is there any way to make an automatically scaling background?

babu198649
12th March 2008, 12:34
hi
i have tried changing background color using style sheets and it works


this->setStyleSheet("background-color:red");

if i try to change background image it does not work


this->setStyleSheet("background-image: url(:/icon/wave.png)");//does not work

or

this->setStyleSheet("QWidget{background-image: url(:/icon/wave.png)}");//does not work

THRESHE
12th March 2008, 13:20
For QWidget and QDialog you should reimplement paintEvent() and do your image painting there as I remember

phillip_Qt
10th April 2008, 09:52
I'm not very sure. But try like
qApp->setStyleSheet("QWidget{background-image: url(:/icon/wave.png)}");
Hope it ll work.