Qlistwidget Adding small controls

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.