Skip to content

Commit 2c8a67f

Browse files
Fix UX in image preview
1 parent 80b5c2f commit 2c8a67f

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/zGui/zdialog.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <QTimer>
1010
#include <QScrollArea>
1111
#include <QLabel>
12+
#include <QPixmap>
1213

1314
using zclipboard::zGui::ZDialog;
1415

@@ -61,12 +62,16 @@ void ZDialog::showZImageDialog(const QImage &image, QWidget *parent) {
6162
zDialog->setWindowTitle("zClipboard Image Viewer");
6263
zDialog->resize(600, 600);
6364

64-
imageLabel->setPixmap(QPixmap::fromImage(image));
65+
QPixmap pixmap = QPixmap::fromImage(image);
66+
QSize maxSize = zDialog->size() * 0.9;
67+
QPixmap scaledPixmap = pixmap.scaled(maxSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
68+
69+
imageLabel->setPixmap(scaledPixmap);
70+
imageLabel->adjustSize();
6571
imageLabel->setAlignment(Qt::AlignCenter);
66-
imageLabel->setScaledContents(true);
6772

6873
scrollArea->setWidget(imageLabel);
69-
scrollArea->setWidgetResizable(true);
74+
scrollArea->setWidgetResizable(false);
7075

7176
zLayout->addWidget(scrollArea, 0, 0);
7277

0 commit comments

Comments
 (0)