import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class TableWidgetDemo(QWidget):
def __init__(self):
super(TableWidgetDemo, self).__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('QTableWidget演示')
self.resize(500,300)
layout=QHBoxLayout()
tableWidget=QTableWidget()
tableWidget.setRowCount(4)
tableWidget.setColumnCount(3)
layout.addWidget(tableWidget)
tableWidget.setHorizontalHeaderLabels(['姓名','性别','体重(kg)'])
textItem=QTableWidgetItem('小明')
tableWidget.setItem(0,0,textItem)
combox=QComboBox()
combox.addItem('男')
combox.addItem('女')
#QSS:Qt StyleSheet Qt样式 像网页的CSS样式
combox.setStyleSheet('QComboBox{margin:5px};')
tableWidget.setCellWidget(0,1,combox)
modifyButton=QPushButton('修改')
modifyButton.setDown(True)
modifyButton.setStyleSheet('QPushButton{margin:5px};')
tableWidget.setCellWidget(0, 2, modifyButton)
self.setLayout(layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
main = TableWidgetDemo()
main.show()
sys.exit(app.exec())
课时68.pyqt5在单元格中放置控件
最新推荐文章于 2025-09-14 20:03:55 发布