[英]How to show an image in a 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文件上的完整路径吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.