如何在QLabel中显示图像
问题描述:
我试图在QLabel中显示资源文件中的图像。所有这些都是从扩展主要核心应用程序的插件发生的。如何在QLabel中显示图像
#include "sampleplugin.h"
#include <QtWidgets>
SamplePlugin :: SamplePlugin()
{
Q_INIT_RESOURCE(pluginresources);
oLContainerWidget = new QWidget();
olWrapper = new QHBoxLayout();
bagIcon(":/sample_plugin_resources/images/Dry-50.png");
oLContainerWidget -> setLayout(olWrapper);
}
void SamplePlugin :: testIcon(const QString &imageUrl)
{
QPixmap pix(imageUrl);
QLabel *sampleIconLabel = new QLabel();
sampleIconLabel -> setPixmap(pix);
olWrapper -> addWidget(sampleIconLabel);
}
该项目编译没有任何错误,但图像不显示。我究竟做错了什么?
谢谢大家提前。
项目结构:
**plugins_dir**
sampleplugin
pluginresources.qrc
sample_plugin_resources
- Dry-50.png
答
检查pix
实际上已加载图像(pix.isNull()
)。您正在从资源路径加载图像,是QRC文件上的完整路径吗?
你能解决问题吗?还有什么可以尝试弄清楚的? – cbuchart