首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QGraphicsPixmapItem不显示图像

QGraphicsPixmapItem不显示图像
EN

Stack Overflow用户
提问于 2011-07-31 17:49:19
回答 1查看 632关注 0票数 0

能帮上忙吗?我只得到一个带有垂直滚动条的空白视图。可以检查代码吗?我认为问题开始于item.setPixmap(像素映射);因为像素映射的图像大小与图像加载到其中的图像大小相同。谢谢

代码语言:javascript
复制
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <poppler-qt4.h>
#include <QGraphicsPixmapItem>
#include <QGraphicsRotation>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
ui->setupUi(this);

QString filename;

Poppler::Document* document = Poppler::Document::load("/home/pc/Documenti/ICS-TR-06-16.pdf");
if (!document || document->isLocked())
{

  // ... error message ....

  delete document;
  return;
}

qDebug("doc %i \n",document->numPages()); //gives 11

// Access page of the PDF file
Poppler::Page* pdfPage = document->page(1);  // Document starts at page 0
if (pdfPage == 0) {
  // ... error message ...
  return;
}

// Generate a QImage of the rendered page
QImage image = pdfPage->renderToImage(72.0,72.0,0,0,pdfPage->pageSize().width(),pdfPage->pageSize().height());
if (image.isNull()) {
  // ... error message ...
  return;
}

qDebug("img %i %i \n",image.width(),image.height()); //gives 612 792
QGraphicsScene* scene=new QGraphicsScene();


QPixmap pixmap;
pixmap=QPixmap::fromImage(image);
qDebug("pix %i %i \n",pixmap.width(),pixmap.height()); //gives 612 792



QGraphicsPixmapItem item;
item.setPixmap(pixmap);
qDebug("itpix %i %i \n",item.pixmap().width(),item.pixmap().height()); //gives 612 792
//qDebug("ite %i %i \n",);

    scene->addItem(&item);
    this->ui->graphicsView->setScene(scene);

 this->ui->graphicsView->show();
// ... use image ...

// after the usage, the page must be deleted
delete pdfPage;
}

MainWindow::~MainWindow()
{
if (document!=0) delete document;
delete ui;
}    
EN

回答 1

Stack Overflow用户

发布于 2011-07-31 18:07:50

乍一看,我看不出这有什么问题。

然而,冒着说出显而易见的风险,你确定PDF的第一页不是空白的吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6888704

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档