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