forked from geekori/pyqt5
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathCellTextAlignment.py
More file actions
51 lines (36 loc) · 1.32 KB
/
CellTextAlignment.py
File metadata and controls
51 lines (36 loc) · 1.32 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
'''
设置单元格的文本对齐方式
setTextAlignment
Qt.AlignRight Qt.AlignBottom
'''
import sys
from PyQt5.QtWidgets import (QWidget, QTableWidget, QHBoxLayout, QApplication, QTableWidgetItem)
from PyQt5.QtCore import Qt
class CellTextAlignment(QWidget):
def __init__(self):
super(CellTextAlignment,self).__init__()
self.initUI()
def initUI(self):
self.setWindowTitle("设置单元格的文本对齐方式")
self.resize(430, 230);
layout = QHBoxLayout()
tableWidget = QTableWidget()
tableWidget.setRowCount(4)
tableWidget.setColumnCount(3)
layout.addWidget(tableWidget)
tableWidget.setHorizontalHeaderLabels(['姓名', '性别', '体重(kg)'])
newItem = QTableWidgetItem('雷神')
newItem.setTextAlignment(Qt.AlignRight | Qt.AlignBottom)
tableWidget.setItem(0,0,newItem)
newItem = QTableWidgetItem('男')
newItem.setTextAlignment(Qt.AlignCenter | Qt.AlignBottom)
tableWidget.setItem(0,1,newItem)
newItem = QTableWidgetItem('190')
newItem.setTextAlignment(Qt.AlignRight)
tableWidget.setItem(0,2,newItem)
self.setLayout(layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
example = CellTextAlignment()
example.show()
sys.exit(app.exec_())