14 #include <QtGui/QPainter> 27 pixmap_ = QPixmap::fromImage(image);
40 float w = pixmap_.width();
41 float h = pixmap_.height();
42 float widthRatio = float(this->rect().width()) / w;
43 float heightRatio = float(this->rect().height()) / h;
45 if(widthRatio < heightRatio)
57 if(w < this->rect().width())
59 offsetX = (this->rect().width() - w)/2.0
f;
61 if(h < this->rect().height())
63 offsetY = (this->rect().height() - h)/2.0
f;
71 QPainter painter(
this);
75 painter.setBrush(brush_);
76 painter.drawRect(this->rect());
83 float ratio, offsetX, offsetY;
84 this->computeScaleOffsets(ratio, offsetX, offsetY);
85 painter.translate(offsetX, offsetY);
86 painter.scale(ratio, ratio);
87 painter.drawPixmap(QPoint(0,0), pixmap_);
void computeScaleOffsets(float &scale, float &offsetX, float &offsetY)
UImageView(QWidget *parent=0)
void setImage(const QImage &image)
virtual void paintEvent(QPaintEvent *event)
void setBackgroundBrush(const QBrush &brush)