-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathWidget.cpp
42 lines (37 loc) · 1.12 KB
/
Widget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <QStandardItemModel>
#include <QObject>
#include "Widget.h"
#include "ui_Widget.h"
#include "MuListItemData.h"
#include "MuItemDelegate.h"
const QStringList icons = {
":/images/HotDog.jpg", ":/images/li.jpg", ":/images/logo.jpg",
":/images/PACT.jpg", ":/images/yang.jpg", ":/images/zhang.jpg",
};
const QStringList singers = {
"MC-Hotdog", "李荣浩", "Author",
"PACT", "杨千嬅", "张震岳",
};
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QStandardItemModel *pModel = new QStandardItemModel();
for (int i=0; i<icons.size(); ++i) {
QStandardItem *pItem = new QStandardItem;
MuItemData itemData;
itemData.singer = singers.at(i);
itemData.songsNb = QString::number(i * i) + "首";
itemData.iconPath = icons.at(i);
pItem->setData(QVariant::fromValue(itemData), Qt::UserRole+1);
pModel->appendRow(pItem);
}
MuItemDelegate *pItemDelegate = new MuItemDelegate(this);
ui->listView->setItemDelegate(pItemDelegate);
ui->listView->setModel(pModel);
}
Widget::~Widget()
{
delete ui;
}