先创建QListWidgetItem:
QListWidgetItem* pListItem1 = new QListWidgetItem(QIcon(":/resources/editor.png"),u8"editor");QListWidgetItem* pListItem2 = new QListWidgetItem(QIcon(":/resources/env.png"),u8"env");QListWidgetItem* pListItem3 = new QListWidgetItem(QIcon(":/resources/help.png"),u8"help");QListWidgetItem* pListItem4 = new QListWidgetItem(QIcon(":/resources/kits.png"),u8"kits");QListWidgetItem* pListItem5 = new QListWidgetItem(QIcon(":/resources/vim.png"),u8"vim");
将项添加进ListWidget:
ui->listWidget->addItem(pListItem1);ui->listWidget->addItem(pListItem2);ui->listWidget->addItem(pListItem3);ui->listWidget->addItem(pListItem4);ui->listWidget->addItem(pListItem5);
创建一个指向其它窗口的指针:
CUserItem* pUser = new CUserItem(this);//this表示父窗口未当前窗口
创建一个Item,并将widget添加进去:
QListWidgetItem* pListItem6 = new QListWidgetItem();ui->listWidget_2->setItemWidget(pListItem6,pUser);