Cloning QListWidgetItem
#include <QtGui>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QListWidget listWidget;
QListWidgetItem *proto=new QListWidgetItem;
proto->setFont(QFont("Times"));
proto->setTextColor(Qt::blue);
proto->setBackgroundColor(Qt::yellow);
QListWidgetItem *name = proto->clone();
name->setText("Antje");
listWidget.insertItem(0,name);
name = proto->clone();
name->setText("Daniel");
listWidget.insertItem(0,name);
name = proto;
name->setText("Barbara");
listWidget.insertItem(0,name);
listWidget.sortItems();
listWidget.show();
return app.exec();
}
Related examples in the same category