-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
36 lines (31 loc) · 867 Bytes
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_button_image_clicked()
{
QString filename = QFileDialog::getOpenFileName(this,tr("Choose"),"",tr("Images(*.png *.jpg *.bmp *.jpeg *.gif)"));
if(QString::compare(filename,QString())!=0)
{
QImage image;
bool valid = image.load(filename);
if(valid)
{
image = image.scaledToWidth(ui->label_image->width(),Qt::SmoothTransformation);
image = image.scaledToHeight(ui->label_image->height(),Qt::SmoothTransformation);
ui->label_image->setPixmap(QPixmap::fromImage(image));
}
else
{
//Error handling
}
}
}