将状态栏添加到状态栏 - Qt

bac*_*m09 1 c++ icons qt

我有一个以下列格式保存的图标:

//icon.h
extern const unsigned char icon[];

//icon.cpp
const unsigned char icon[]={0x17,0x3f,0x0c,....,0x10,0x06}
Run Code Online (Sandbox Code Playgroud)

现在我想将此图标添加到状态栏.

我该怎么做?

谢谢.

Mor*_*sen 8

首先创建一个加载图标数据的小部件,就像您在其上设置QPixmap的QLabel一样.该图像的格式是什么?您必须使用其中一个构造函数将其加载到pixmap中,或者您可以尝试加载它loadFromData().

然后将该小部件添加到状态栏,如下所示:

statusBar()->addWidget(yourIconWidget);
Run Code Online (Sandbox Code Playgroud)

看看statusBar(),addWidget()addPermanentWidget().

如何创建窗口小部件的示例可以是:

QPixmap *pixmap = new QPixmap;

// Note that here I don't specify the format to make it try to autodetect it, 
// but you can specify this if you want to. 
pixmap->loadFromData(icon, sizeof(icon) / sizeof(unsigned char));

QLabel *iconLbl = new QLabel;
iconLbl->setPixmap(pix);

statusBar()->addWidget(iconLbl);
Run Code Online (Sandbox Code Playgroud)

如上所述,指定格式在此处详细说明.