c++ - Using images in QListWidget, is this possible? -
i using qt create chat messenger client. display list of online users, i'm using qlistwidget
, created this:
listwidget = new qlistwidget(horizontallayoutwidget); listwidget->setobjectname("userlist"); qsizepolicy sizepolicy1(qsizepolicy::preferred, qsizepolicy::expanding); sizepolicy1.sethorizontalstretch(0); sizepolicy1.setverticalstretch(0); sizepolicy1.setheightforwidth(listwidget->sizepolicy().hasheightforwidth()); listwidget->setsizepolicy(sizepolicy1); listwidget->setminimumsize(qsize(30, 0)); listwidget->setmaximumsize(qsize(150, 16777215)); listwidget->setbasesize(qsize(100, 0)); listwidget->setcontextmenupolicy(qt::customcontextmenu);
users shown refreshing list, this: (note: there different channels, different userlists, refreshing efficient thing do, far know.)
void fmessenger::refreshuserlist() { if (currentpanel == 0) return; listwidget = this->findchild<qlistwidget *>(qstring("userlist")); listwidget->clear(); qlist<fcharacter*> charlist = currentpanel->charlist(); qlistwidgetitem* charitem = 0; fcharacter* character; foreach(character, charlist) { charitem = new qlistwidgetitem(character->name()); // charitem->seticon(qicon(":/images/status.png")); listwidget->additem(charitem); } }
this has worked perfectly. line commented out 1 have problems with: current goal able display user's online status image, represents whether busy, away, available, etc. using seticon()
absolutely nothing though, apparently; items still show used to, without icons.
i'm aware not way function needs used, have found little documentation online, , absolutely no useful examples of implementations. question is, can me fixing problem?
this how may conduct debugging:
- try constructor has both icon , text arguments.
- try use icon in context ensure displayable (construct qicon same argument , use elsewhere, e.g. qlabel!).
- use icon() qlistwidgetitem receive icon , @ qicon.
- create new qlistwidget, change nothing, , ordinarily add stock items in mainwidget's constructor. see if icons show there.
Comments
Post a Comment