PDA

View Full Version : how to change BackGround image on a stacked widget



mcrahr
9th February 2010, 14:19
Hi.

I'm using a stacked widget with 6 page on.

I would like to change the background to a image that I get from a server, the image is put into a pixmap

I have the following code, and it works ok, but there must be a more easy way to do this, I did try to change the palette but I can't get it to work

void MainWindow::on_receive_albumcover(QPixmap *p)
{
qDebug()<<"Got a picture";
//ui->label_7->setPixmap(*p);
p->save("cover_test.jpg");
ui->stackedWidget->setStyleSheet("QWidget#page{border-image: url(cover_test.jpg) ;}QWidget{background-color: rgb(44, 44, 44);}");
}


I manage to get this code working, but only if I do not have any thing in the stylesheet. as soon as I put something into the stylesheet in the desigen it do not work anymore.

Code for change of palette

ui->stackedWidget->setAutoFillBackground(true);
QPalette pal(ui->stackedWidget->palette());
pal.setBrush(QPalette::Window,QBrush(*p));
ui->stackedWidget->setPalette(pal);



So if I put this into the stylesheet. The palette do not work anymore

QPushButton:pressed{
background-color: qlineargradient(spread:pad, x1:0.494, y1:1, x2:0.523, y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));
border-style:inset;
border-top: 1px solid gray;
border-right: 1px solid gray;
border-bottom: 1px solid white;
border-left: 1px solid white;
border-radius: 10px;

Question why is this ?
and is there a way to use the pixmap pointer direct to the stylesheet
and one last thing, the stylesheet in ui-stackedwidget is quite big, and it looks like you need to write everything if you use setStyleSheet.





Br.
Michael Rahr

high_flyer
9th February 2010, 17:15
Question why is this ?
Because the style sheet overrides the palette.
You either use a stylesheet, or you don't.

Your first code is the way to go, if you want to use style sheets.

mcrahr
9th February 2010, 18:36
Thanks.

So just to understand 100% If I use a stylesheet, and I want to dynamic change a image, that is not located in a resource file or on the disk but in a pixmap, then I need to save it to a file, like I already do, it is not possible to use a pointer to a pixmap in the setStylesheet

high_flyer
10th February 2010, 08:38
is not possible to use a pointer to a pixmap in the setStylesheet
not to my knowledge.