【发布时间】:2013-03-06 01:21:36
【问题描述】:
我还在学习 Qt,我在 Qt 中做了一个小项目,我使用 qt ui 设计器创建了一个简单的 ui,并使用 QGraphicsView 显示由 QFileDialog 加载的图像,但是当我将加载的图像文件添加到 QgraphicsScene 时,图像未显示在图形视图中。图形视图保持空白,请帮助我,谢谢!
Project2::Project2(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui = new Ui::Project2Class;
ui->setupUi(this);
this->scene = new QGraphicsScene;
this->scene->setSceneRect(0, 0, 649, 459);
connect(ui->mapLoaderButton, SIGNAL(clicked()), this, SLOT(GetfilePath()));
ui->graphicsView->setScene(this->scene);
}
void Project2::GetfilePath()
{
QString filePath = QFileDialog::getOpenFileName(this, tr("Select file"), "", tr("Files (*.jpg*)"));
if (filePath.isNull() == false)
{
QImage image(filePath);
QSize size = image.size();
ui->graphicsView->scene()->addItem(&QGraphicsPixmapItem(QPixmap::fromImage(image)));
ui->graphicsView->scene()->update();
ui->graphicsView->viewport()->update();
}}
【问题讨论】:
标签: c++ qt qgraphicsview qgraphicsscene