-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqtable_widget_example.py
More file actions
95 lines (75 loc) · 3.02 KB
/
Copy pathqtable_widget_example.py
File metadata and controls
95 lines (75 loc) · 3.02 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import PyQt4
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QFont, QTableWidgetItem
app = QtGui.QApplication([])
columns = ['Column 0', 'Column 1', 'Column 2']
items = [['Row%s Col%s' % (row, col) for col in range(len(columns))] for row in range(1)]
view = QtGui.QTableWidget()
afont = PyQt4.QtGui.QFont()
afont.setFamily("Arial Black")
afont.setPointSize(30)
# styleSheet = "QHeaderView {" \
# "spacing: 10px;" \
# "background-color: yellow;" \
# "color: white;" \
# "border: 1px solid red;" \
# "margin: 1px;" \
# "text-align: right;" \
# "font-family: arial;" \
# "font-size: 12px; }" \
# bFont=PyQt4.QtGui.QFont("Arial", 20, QFont.Bold)
# view.horizontalHeader().setStyleSheet("QHeaderView {font-size: 30pt; color: blue; background-color:lightblue;}")
# view.horizontalHeader().setStyleSheet(styleSheet)
# styleSheet =
font_type = 'bold'
background_color = 'blue'
font_size = 15
foreground_color = 'white'
font_weight = 'bold'
# str_sub = "font-weight: %s; color: %s; font-size: %dpx; background-color: %s;" % (font_weight, foreground_color, font_size, background_color)
str_sub = ""
if font_type is not None:
str_sub = "font-weight: {};".format(str.lower(font_type))
if foreground_color is not None:
str_sub += "color: {};".format(str.lower(foreground_color))
if background_color is not None:
str_sub += "background-color: {};".format(str.lower(background_color))
if font_size is not None:
str_sub += "font-size: {}pt;".format(font_size)
ss = "QHeaderView::section {%s}" % str_sub
# ss = "QHeaderView::section {color: white;font-size: 30pt; background-color: red;}"
# ss = "QHeaderView::section {font-weight: %s; color: %s; font-size: %dpx; background-color: %s;}" % \
# (font_weight, foreground_color, font_size, background_color)
# view.horizontalHeader().setStyleSheet(ss)
# view.horizontalHeader().setFont(bFont)
# view.horizontalHeader().setStyleSheet("QHeaderView { font-size: 30pt; }")
# view.horizontalHeader().setFont(afont)
# view.horizontalHeader().setStyleSheet("color: blue;")
view.setColumnCount(len(columns))
view.setHorizontalHeaderLabels(columns)
view.setRowCount(len(items))
for row, item in enumerate(items):
for col, column_name in enumerate(item):
item = QtGui.QTableWidgetItem("%s" % column_name)
view.setItem(row, col, item)
view.setRowHeight(row, 16)
fnt = QFont()
fnt.setPointSize(15)
fnt.setBold(True)
fnt.setFamily("Arial")
item1 = view.horizontalHeaderItem(0)
item1.setForeground(QtGui.QColor(255, 0, 0))
item1.setFont(fnt)
item2 = view.horizontalHeaderItem(1)
item2.setForeground(QtGui.QColor(0, 255, 0))
item2.setFont(fnt)
item3 = view.horizontalHeaderItem(2)
item3.setForeground(QtGui.QColor(255, 0, 255))
# item1 = QTableWidgetItem('red')
# item1.setBackground(QtGui.QColor(255, 0, 0))
# item1.setForeground(QtGui.QColor(255, 0, 0))
view.setHorizontalHeaderItem(0, item1)
view.setHorizontalHeaderItem(1, item2)
view.setHorizontalHeaderItem(2, item3)
view.show()
app.exec_()