2011-07-31 66 views
0

可以幫忙嗎?我只是用垂直滾動條獲得空白視圖。可以檢查代碼?我認爲麻煩從item.setPixmap(pixmap)開始;因爲像素圖與圖像加載到其中的圖像大小相同。謝謝QGraphicsPixmapItem不顯示圖像

#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; 
}  

回答

0

我第一眼看不出有什麼問題。

但是,冒着明顯的風險,你確定PDF的第一頁不是空白嗎?

+0

是的,與jpg圖像相同 – P5music

+0

它與scene-> addPixmap(pixmap); – P5music