When writing a simple file browser, encountered a problem, want to implement the new folder as a general File Manager, the folder icon below an edit box prompts the user to name the folder (for example), but do not know how to add the Qlineedit control to the unit item Qlistwidgetitem. Check for a long time QT help document, finally found Qlistwidget::setitemwidget (), just tried, successfully added, still satisfied. If you have a better way, please let me know.
void Qlistwidget::setitemwidget (Qlistwidgetitem * Item, Qwidget * widget)
Sets the widget to display in a given project.
This feature can only be used to display static content in the location of a list widget project. If you want to display custom dynamic content or perform custom editor parts, use Qlistview and subclass Qitemdelegate instead.
This feature introduces QT 4.1.
Key code:
///images can be changed to a folder iconintMainintargcChar* argv[]) {qapplication app (ARGC,ARGV); Qlistwidget *listwidget =NewQlistwidget (); Listwidget->setspacing (Ten); Listwidget->setviewmode (Qlistview::iconmode); Listwidget->seticonsize (Qsize ( -, -)); Qpixmap pix1 (QString (":/list/image/1.jpg")); Qpixmap pix2 (":/list/image/2.jpg"); Qlistwidgetitem *item1 =NewQlistwidgetitem (Qicon (pix1.scaled (Qsize ( -, -))),"Picture1"); Qlistwidgetitem *item2 =NewQlistwidgetitem (Qicon (pix2.scaled (Qsize ( -, -))),"Picture2"); qlineedit* line =NewQlineedit;//Create partsListwidget->additem (ITEM1); Listwidget->additem (ITEM2);//Add Items FirstItem1->setsizehint (Qsize ( -, -)); Item2->setsizehint (Qsize ( -, -)); Listwidget->setitemwidget (Item2,line);//Add parts//Listwidget->removeitemwidget (ITEM2);Listwidget->show (); App.exec ();return 0;}
void Qlistwidget::removeitemwidget (Qlistwidgetitem * Item)
Used to remove the added part
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Qlistwidget Adding small controls