PDA

View Full Version : How to set background image with no-repeat (without using CSS)



forrestfsu
16th October 2006, 16:51
I currently have code that sets a widgets background to a desired image. However, by default it is tiling the image. I'm trying to make it so that it does not repeat. I was able to use CSS stylesheet's to do this, but it ended up lagging my program on load. Therefore, I decided to use a different method. Below is the code I have so far, and if anyone can help me figure out how to make it not repeat the image, I would appreciate it:


QPalette p = this->palette();
p.setBrush(QPalette::Window, QPixmap(QString(":imageLocation")));
this->setPalette(p);
this->setAutoFillBackground(true);

wysota
16th October 2006, 19:43
Is it a custom widget? Maybe you can paint it yourself?

forrestfsu
16th October 2006, 20:46
Although a weak solution, this is what got the job done:

Through Designer:
I simply created a QLabel and set the Pixmap of the label to be my background image. I then made sure that this new label was moved to the back, so that it was behind all other form items.

ysilent
18th May 2012, 11:12
QT cannot do too much.
Cannot move icon/background image/border image to a fixed position.
And now, it stop you do it outside a customer widget.
So the only way is to paint by yourself, perfect.