PyQt5绘制表格
PyQt5绘制表格需要用到QTableWidget控件,QTableWidget可以添加行,添加列,添加表格图片等。而且可以自定义表格样式。非常好用。
我们先看下图吧
源码
# -*- coding:utf-8 -*-
”’
TableWidget
”’
__author__ = ‘py40.com’
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QApplication, QDesktopWidget, QTableWidget, QHBoxLayout, QTableWidgetItem, \
QComboBox, QFrame
from PyQt5.QtGui import QFont, QColor, QBrush, QPixmap
class TableSheet(QWidget):
def __init__(self):
super().__init__()
self.initUi()
def initUi(self):
horizontalHeader = [“编号”, “姓名”, “性别”, “年龄”, “职业”]
table = QTableWidget()
table.setColumnCount(5)
table.setRowCount(2)
table.setHorizontalHeaderLabels(horizontalHeader)<