16 |
void PictureView::paintEvent ( QPaintEvent* event) |
void PictureView::paintEvent ( QPaintEvent* event) |
17 |
{ |
{ |
18 |
Q_UNUSED(event); |
Q_UNUSED(event); |
19 |
|
|
20 |
|
QSize s = this->size(); |
21 |
|
|
22 |
|
QBrush blackBrush(Qt::black); |
23 |
|
|
24 |
QPainter painter(this); |
QPainter painter(this); |
25 |
painter.drawPixmap(0,0,image); |
painter.fillRect( QRect(0,0,s.width(), s.height()), blackBrush); |
26 |
|
|
27 |
|
int x = 0; |
28 |
|
int y = 0; |
29 |
|
|
30 |
|
if (image.width() < s.width() ) { |
31 |
|
x = (s.width() - image.width()) / 2; |
32 |
|
} |
33 |
|
if (image.height() < s.height() ) { |
34 |
|
y = (s.height() - image.height()) / 2; |
35 |
|
} |
36 |
|
|
37 |
|
|
38 |
|
painter.drawPixmap(x,y,image); |
39 |
painter.end(); |
painter.end(); |
40 |
} |
} |
41 |
|
|
56 |
pixmap.loadFromData( data ); |
pixmap.loadFromData( data ); |
57 |
} |
} |
58 |
|
|
59 |
QPixmap scaledImage = pixmap.scaledToHeight(size().height(), Qt::SmoothTransformation ); |
QPixmap scaledImage = pixmap.scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); |
60 |
|
|
61 |
image = scaledImage; |
image = scaledImage; |
62 |
this->repaint(); |
this->repaint(); |