-
Notifications
You must be signed in to change notification settings - Fork 1
/
TableViewEx.cpp
41 lines (37 loc) · 1.63 KB
/
TableViewEx.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
#include "TableViewEx.h"
TableViewEx::TableViewEx(QWidget *parent) : QTableView(parent)
{
init();
}
void TableViewEx::init()
{
setStyleSheet("QTableView {border: 1px solid #31343B; background: #484C55;}\
QTableView::item {font: 15pt Microsoft YaHei; color: #CCCCCC;\
padding-left: 5px; padding-right: 5px; border: none; background: #484C55;\
border-right: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;}\
QTableView::item:selected {background: #4EB485; color:#FFFFFF}\
QTableView::item:selected:!active {color: #FFFFFF;}\
QHeaderView::section{background:#484C55; color:#FFFFFF; height:40px; font:12pt Microsoft YaHei;}\
QHeaderView{background:#484C55}");
setSelectionBehavior(QAbstractItemView::SelectRows);
setSelectionMode(QAbstractItemView::SingleSelection);
setSortingEnabled(false);
verticalHeader()->hide();
setWordWrap(false);
setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
setShowGrid(false);
setEditTriggers(QAbstractItemView::NoEditTriggers);
horizontalHeader()->setHighlightSections(false);
setAlternatingRowColors(true);
setFrameShape(QFrame::NoFrame);
horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
}
void TableViewEx::setTableModel(QAbstractTableModel *model, bool isInteractive)
{
this->setModel(model);
if(isInteractive)
{
this->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
}
}