qt中如何显示图片,下面的代码可供参考
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QImage>
#include <QPixmap>
#include <QLabel>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
//显示图片
QImage *image=new QImage("E:/Qt_Program/Chrysanthemum.jpg");
QLabel *label=new QLabel(this);
label->setGeometry(0,0,500,500);
label->setPixmap(QPixmap::fromImage(*image));
//label->setPixmap(QPixmap("E:/Qt_Program/Chrysanthemum.jpg"));
label->show();
}