-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtableview.h
69 lines (61 loc) · 2.13 KB
/
tableview.h
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef TABLEVIEW_H
#define TABLEVIEW_H
#include <QTableWidget>
#include <QHeaderView>
#include "pix.h"
extern QString blue;
class TableView : public QTableWidget
{
Q_OBJECT
public:
Pix p;
TableView()
{
hide();
verticalHeader()->setVisible(false);
verticalHeader()->setDefaultSectionSize(22);
horizontalHeader()->setStretchLastSection(true);
setShowGrid(false);
setEditTriggers(QAbstractItemView::NoEditTriggers);
setSelectionBehavior(QAbstractItemView::SelectRows);
//setSelectionMode(QAbstractItemView::MultiSelection);
setAlternatingRowColors(true);
resizeRowsToContents();
setStyleSheet("TableView {border:0px;alternate-background-color:#F4F4F4;color:#444;font-size:12px;}");
QPalette p = palette();
p.setColor(QPalette::Highlight, QColor(blue));
setPalette(p);
QStringList header;
header << "" << "Title" << "State" << "Time" << "Artist" << "Album" << "Genre" << "Year" << "";
setRowCount(1);
setColumnCount(9);
setColumnWidth(0,20);
setColumnWidth(1,200);
setColumnWidth(2,40);
setColumnWidth(3,40);
setColumnWidth(4,150);
setColumnWidth(5,150);
setColumnWidth(6,200);
setColumnWidth(7,40);
setHorizontalHeaderLabels(header);
}
void setData(QVariantList songs)
{
setRowCount(songs.length() + 10);
int i = 0;
foreach (QVariant s, songs)
{
QVariantMap song = s.toMap();
QTableWidgetItem *title = new QTableWidgetItem(song["title"].toString());
title->setData(32,s);
setItem(i,1,title);
setItem(i,3,new QTableWidgetItem(p.timeFromSecconds(song["duration"].toInt())));
setItem(i,4,new QTableWidgetItem(song["artist"].toString()));
setItem(i,5,new QTableWidgetItem(song["album"].toString()));
setItem(i,6,new QTableWidgetItem(song["genre"].toString()));
setItem(i,7,new QTableWidgetItem(QString::number(song["year"].toInt())));
i++;
}
}
};
#endif // TABLEVIEW_H