QScrollArea - 标签中未显示 TIFF 图像
QScrollArea - TIFF image is not shown in the label
我实际上正在尝试使用 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 图像...只有一个空白的灰色 window。
你能帮帮我吗?
您使用的 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.
我实际上正在尝试使用 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 图像...只有一个空白的灰色 window。
你能帮帮我吗?
您使用的 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.