Reputation: 1483
I am developing a custom plugin in Qt and there is this situation where I have to build a widget which has some an Image on it. So I am using QLabel as base class for my custom widget. Here's the code for paint event
QPixmap pic("/general/source/pic.png");
setAutoFillBackground(true);
QPalette palette;
palette.setBrush(QPalette::Window, QBrush(pic));
this->setPalette(palette);
Now the image is rendered on the QLabel, but this is not what I desired.
Please help.
Upvotes: 2
Views: 15071
Reputation: 14941
If you have a custom widget class, you could override the paintEvent and do the proper drawing at that point. I don't know if you could just draw the pixmap scaled to the proper size and call the parent's class to finish the drawing, or if you'd have to do all of it yourself.
Upvotes: -1
Reputation: 8958
Assuming you can get the size of your control you can scale your pixmap before you set it in the brush using
pic.scaled ( width, height, Qt::IgnoreAspectRatio, Qt::FastTransformation )
This returns another QPixmap which you can pass to your QBrush.
Just for reference, you can also use a style sheet to set the border image for your control.
border-image: url( yourImage);
Upvotes: 3