QPixmap as background of QWidget
Hi all.
I have a little problem with my application, so I'm working at program, that can be used to take screenshots of desktop, but only area which I select, next - save image to file/share via mail etc. My current layout exclude use QLabel element and set his pixmap in my viewer, so I must use QWidget object. I read documentation and I understand, that QWidget's background can be change only with CSS using. But I have no idea what I should do that, when I have an image in QPixmap; of course I want do it without saving this screenshot on hard disk.
Code:
originalPixmap
= QPixmap::grabWindow(desk.
winId());
ui->mainWidget->setStyleSheet("background-image: ???"); //what here?
Any ideas?
Thanks.
//Ok, it was easier than I thought. This is the answer:
Code:
originalPixmap
= QPixmap::grabWindow(desk.
winId());
palette.
setBrush((this)->backgroundRole
(),
QBrush(originalPixmap
));
(this)->setPalette(palette);
Re: QPixmap as background of QWidget
Alternatively, you can implement the paintEvent() for your widget, and inside it call QPainter::drawPixmap().
If you set the palette's background brush the way you are now doing, I think the pixmap will be tiled (or clipped) if it is a different size from the widget you use to display it. When you use QPainter, you can scale the pixmap to fit the window if that's what you want.
Re: QPixmap as background of QWidget
I think it should also work to use the label as a container widget. Sounds weird but a QLabel is a QFrame and that is a very common container.
Cheers,
_