diff options
| author | David Edmundson <[email protected]> | 2015-03-11 17:16:49 +0100 |
|---|---|---|
| committer | David Edmundson <[email protected]> | 2015-03-25 12:31:49 +0100 |
| commit | 78cb2cf14a38c0c24fc8adb51f567bd9469917a7 (patch) | |
| tree | 7594954deddb5bcbfcf53bbc775c2fd8482a35b8 | |
| parent | adeaab9745c681e99b6bf7b3144a6fc0878a387f (diff) | |
Center align pixmaps in a high DPR friendly way
| -rw-r--r-- | src/panels/information/pixmapviewer.cpp | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/panels/information/pixmapviewer.cpp b/src/panels/information/pixmapviewer.cpp index 0053e43f9..0874f2b39 100644 --- a/src/panels/information/pixmapviewer.cpp +++ b/src/panels/information/pixmapviewer.cpp @@ -23,6 +23,7 @@ #include <QPainter> #include <QPixmap> +#include <QStyle> PixmapViewer::PixmapViewer(QWidget* parent, Transition transition) : QWidget(parent), @@ -94,9 +95,6 @@ void PixmapViewer::paintEvent(QPaintEvent* event) const int scaledWidth = static_cast<int>((m_oldPixmap.width() * (1.0 - value)) + (m_pixmap.width() * value)); const int scaledHeight = static_cast<int>((m_oldPixmap.height() * (1.0 - value)) + (m_pixmap.height() * value)); - const int x = (width() - scaledWidth ) / 2; - const int y = (height() - scaledHeight) / 2; - const bool useOldPixmap = (m_transition == SizeTransition) && (m_oldPixmap.width() > m_pixmap.width()); const QPixmap& largePixmap = useOldPixmap ? m_oldPixmap : m_pixmap; @@ -105,12 +103,11 @@ void PixmapViewer::paintEvent(QPaintEvent* event) scaledHeight, Qt::IgnoreAspectRatio, Qt::FastTransformation); - painter.drawPixmap(x, y, scaledPixmap); + + style()->drawItemPixmap(&painter, rect(), Qt::AlignCenter, scaledPixmap); } } else { - const int x = (width() - m_pixmap.width() ) / 2; - const int y = (height() - m_pixmap.height()) / 2; - painter.drawPixmap(x, y, m_pixmap); + style()->drawItemPixmap(&painter, rect(), Qt::AlignCenter, m_pixmap); } } |
