PDA

View Full Version : set backgorund image on main window



narumi
16th February 2008, 05:43
i have a problem to set a background image on main window. i discovered that qt can use css to give some appearance. for my application i have created the image and put in into folder name image in source code folder. i have successfully code the css syntax

QWidget#centralwidget { background-image: url(:/image/mainbg2.png); background-repeat: repeat-x; }
when I click apply there nothing happen on my main window. my question here is does this thing work on the spot or we need to compile first to see the result?

marcel
16th February 2008, 06:51
Yes, you need to recompile, because the resource will be compiled and embedded in the application. And how else would you be able to set a stylesheet for a widget without setStylesheet and recompiling?

narumi
17th February 2008, 00:03
owh... actually I used qt designer and I did set the style through it. Pardon the code I've paste before. Its a wrong code to be put into through designer, Ive fixed it.

Now I have some more question, do we need to put the image file into resource (.qrc file)?

marcel
17th February 2008, 00:06
Just add a reference to it(it's path). It will be embedded in the application at compile time.