[英]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.