2 回答
TA贡献1784条经验 获得超2个赞
我找到了解决方案。我将这一行添加到...
def data(self,index,role=QtCore.Qt.DisplayRole):
col = index.column()
customer = self.customers[index.row()]
if role == QtCore.Qt.DisplayRole:
if col == 0:
return QtCore.QVariant(customer.name)
elif col == 1:
return QtCore.QVariant(customer.number)
elif col == 2:
return QtCore.QVariant(customer.status)
return QtCore.QVariant()
# ADDED LINES
elif role == QtCore.Qt.TextAlignmentRole:
return QtCore.Qt.AlignCenter
###
TA贡献1842条经验 获得超21个赞
没有找到在 QTableView 上创建表格的方法,但是对于每个项目设置,此代码都可以对齐;
data = QTableWidget(["17776661122"])
table.setItem(x,y,data).setTextAlignment(Qt.AlignHCenter)
添加回答
举报