-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelegate.cpp
67 lines (55 loc) · 2.06 KB
/
delegate.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
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
#include "delegate.h"
tableDelegate::tableDelegate(int size, int w, QObject *parent)
: QStyledItemDelegate(parent)
{
this->size = size;
this->w = w;
}
QWidget *tableDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex &/* index */) const
{
QStandardItemModel *model = new QStandardItemModel(1, size);
QTableView *editor = new QTableView(parent);
QHeaderView *header = editor->horizontalHeader();
header->hide();
QHeaderView *header2 = editor->verticalHeader();
header2->hide();
editor->setModel(model);
for (int column = 0; column < size; ++column) {
editor->setColumnWidth(column, w/(size));
}
if(!size)
editor->setStyleSheet("QTableView { background-color: grey; selection-color: black; }");
else
editor->setStyleSheet("QTableView { background-color: #222326; selection-color: black; }");
editor->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
connect(editor, SIGNAL(pressed(const QModelIndex &)), this, SLOT(update(const QModelIndex &)));
editor->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
return editor;
}
void tableDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
QTableView *subTable = static_cast<QTableView*>(editor);
}
void tableDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QTableView *subTable = static_cast<QTableView*>(editor);
//model->setData(index, 1, Qt::EditRole);
}
void tableDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}
void tableDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QStyledItemDelegate::paint(painter, option, index);
}
void tableDelegate::update(const QModelIndex &index)
{
std::cout << index.column() << std::endl;
}