【问题标题】:How to show an image in a QLabel如何在 QLabel 中显示图像
【发布时间】:2017-03-06 21:26:11
【问题描述】:

我正在尝试在 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  

【问题讨论】:

    标签: c++ image qt plugins


    【解决方案1】:

    检查pix 是否实际加载了图像(pix.isNull())。您正在从资源路径加载图像,这是您的 QRC 文件上的完整路径吗?

    【讨论】:

    • 你能解决这个问题吗?还有什么想弄清楚的吗?
    猜你喜欢
    • 2012-06-14
    • 2014-10-13
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多