I have this code
super(ManifestModel, self).__init__(parent, db)
def flags(self, index):
if (index.column() == 4):
return QtCore.Qt.ItemIsEnabled
elif (index.column() == 6):
return QtCore.Qt.ItemIsEnabled
elif (index.column() == 3):
return QtCore.Qt.AlignHCenter
else:
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
class ManifestModel(QtSql.QSqlTableModel):
def __init__(self, parent=None, db=QtSql.QSqlDatabase()):
super(ManifestModel, self).__init__(parent, db)
def flags(self, index):
if (index.column() == 4):
return QtCore.Qt.ItemIsEnabled
elif (index.column() == 6):
return QtCore.Qt.ItemIsEnabled
elif (index.column() == 3):
return QtCore.Qt.AlignHCenter
else:
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
To copy to clipboard, switch view to plain text mode
when I run it I get an error:
builtins.TypeError: invalid result from ManifestModel.flags(), AlignmentFlag cannot be converted to PyQt5.QtCore.ItemFlags in this context
In the same routine that uses ManifestModel I have the code:
ui.
label = QtWidgets.
QLabel(ui.
page)ui.
label.
setGeometry(QtCore.
QRect(308,
0,
131,
20))ui.label.setAlignment(QtCore.Qt.AlignCenter)
ui.label = QtWidgets.QLabel(ui.page)
ui.label.setGeometry(QtCore.QRect(308, 0, 131, 20))
ui.label.setAlignment(QtCore.Qt.AlignCenter)
To copy to clipboard, switch view to plain text mode
So what do I have to do to change the alignment in a QTableView column?
Bookmarks