[英]Add icon to status bar - Qt
I have an icon that is saved in a format: 我有一个以以下格式保存的图标:
//icon.h
extern const unsigned char icon[];
//icon.cpp
const unsigned char icon[]={0x17,0x3f,0x0c,....,0x10,0x06}
Now i want to add this icon to the status bar. 现在,我想将此图标添加到状态栏中。
How do i do it? 我该怎么做?
Thank you. 谢谢。
First create a widget that loads the icon data, like a QLabel on which you set a QPixmap . 首先创建一个小部件来加载图标数据,例如QLabel,在其上设置QPixmap 。 What format is that image in?
该图像采用什么格式? You will have to load it into your pixmap using one of the constructors, or you could try loading it with
loadFromData()
. 您将必须使用构造函数之一将其加载到pixmap中,或者可以尝试使用
loadFromData()
加载它。
Then add that widget to the status bar like so: 然后将该小部件添加到状态栏中,如下所示:
statusBar()->addWidget(yourIconWidget);
Have a look at statusBar()
, addWidget()
and addPermanentWidget()
. 看一下
statusBar()
, addWidget()
和addPermanentWidget()
。
An example of how to create the widget could be: 如何创建窗口小部件的示例可能是:
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);
Specifying the format, as I mentioned above, is elaborated upon here . 如前所述, 这里详细说明了指定格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.