Reputation: 1811
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.
Upvotes: 1
Views: 7688
Reputation: 7613
First create a widget that loads the icon data, like a QLabel on which you set a 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()
.
Then add that widget to the status bar like so:
statusBar()->addWidget(yourIconWidget);
Have a look at statusBar()
, addWidget()
and 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.
Upvotes: 8