2015-09-21 37 views
0

我實際上正在嘗試開發一個使用Qt 5.5的圖形用戶界面(GUI),其目標是加載和打開Tiff圖像(16.1 MB)。QScrollArea - 標籤中沒有顯示TIFF圖像

我已成功加載並顯示使用此代碼的TIFF圖像:

int main(int argc, char *argv[]) 
{ 
QApplication app(argc, argv); 
QWidget window; 

QLabel *label = new QLabel(&fenetre); 
QPixmap pixmap("D:/IS5337_2_010_00092.tif"); 
label->setPixmap(pixmap); 
label->resize(pixmap.size()); 

window.show(); 

return app.exec(); 
} 

然而,當我試圖添加使用此代碼scrollarea:

int main(int argc, char *argv[]) 
{ 
QApplication app(argc, argv); 
QWidget window; 

QLabel *label = new QLabel(&fenetre); 
QPixmap pixmap("D:/IS5337_2_010_00092.tif"); 
label->setPixmap(pixmap); 
label->resize(pixmap.size()); 

QScrollArea *scrollArea = new QScrollArea; 
scrollArea->setBackgroundRole(QPalette::Light); 
scrollArea->setWidget(label); 

window.show(); 

return app.exec(); 
} 

它並沒有在所有的工作。 GUI沒有顯示TIFF圖像...只有一個空的灰色窗口。

請問您能幫我嗎?

回答

1

的scrollArea反對你使用應該與一些親代部件連接:

// in that case we have window object of QWidget type that is running as 
// main window for the app and that has label for embedding the pixmap in it 

QScrollArea *scrollArea = new QScrollArea(&window); // set window as parent for scroll 
scrollArea->setBackgroundRole(QPalette::Light); 

QLabel *label = new QLabel; // (scrollArea) either set scroll as parent for label 
// put the image in label, etc. 
scrollArea->setWidget(label); // or set is as widget for scroll 
// put the image in label, etc. 
+0

它的工作原理!非常感謝亞歷山大。 –

+0

接受和upvote? – AlexanderVX

+0

是的,它完美的作品! –