[英]How to show an image in a QLabel
I'm trying to show an image from a resource file in a QLabel . 我正在尝试从QLabel中的资源文件显示图像。 All this is happenning from a plugin that extends the main core application.
所有这些都是通过扩展主核心应用程序的插件发生的。
#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);
}
The project compiles without any errors, but the image doesn't show. 该项目编译没有任何错误,但是图像没有显示。 What am I doing wrong?
我究竟做错了什么?
Thank you all in advance. 谢谢大家。
The project structure: 项目结构:
**plugins_dir**
sampleplugin
pluginresources.qrc
sample_plugin_resources
- Dry-50.png
Check that pix
has actually loaded the image ( pix.isNull()
). 检查
pix
是否实际加载了图像( pix.isNull()
)。 You are loading the image from a resource path, is that the complete path on your QRC file? 您是从资源路径加载图像,这是QRC文件上的完整路径吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.