Reputation: 217
I'm working with Qt 4.7 , I set a QWidget's background-image CSS an image from my qrc.
The problem is the image is High res , and only the upper left part of it is showing , I can't get it to scale down to fit. In CSS3 I saw a "background-size : contain" property but I fear it doesn't work in Qt 4.7.
Couldn't find a way to make the image fit the window. Any ideas ? I don't mind doing it programmatically .
Thanks
Upvotes: 5
Views: 20175
Reputation: 7891
You can reimplement paintEvent
:
void Widget::paintEvent(QPaintEvent *e)
{
QPainter painter(this);
painter.drawPixmap(0, 0, QPixmap(":/new/prefix1/picture001.png").scaled(size()));
QWidget::paintEvent(e);
}
Upvotes: 5
Reputation: 3713
If the QFrame is the same aspect ratio as the image you can use CSS on the QFrame like this:
QFrame
{
border-image: url(:/images/myimage.png) 0 0 0 0 stretch stretch;
border-width: 0px;
}
Upvotes: 6