【问题标题】:QScrollArea - TIFF image is not shown in the labelQScrollArea - TIFF 图像未显示在标签中
【发布时间】:2015-09-22 02:57:05
【问题描述】:

我实际上是在尝试使用 Qt 5.5 开发图形用户界面 (GUI),其目标是加载和打开 Tiff 图像 (16.1 MB)。

我已使用此代码成功加载并显示 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();
}

但是,当我尝试使用此代码添加滚动区域时:

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 图像......只有一个空的灰色窗口。

你能帮帮我吗?

【问题讨论】:

    标签: image qt tiff qwidget qscrollarea


    【解决方案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.
    

    【讨论】:

      猜你喜欢
      • 2017-12-16
      • 1970-01-01
      • 2012-06-14
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      • 2017-05-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多