Edward_Lipson | 2021-04-04 13:42:52 UTC | #1
How can I align the currency value in a column? QAbstractTableModel.data() just has strings to return so I get an error trying to .setAlignment() there. The delegate has no 'role' parm to align for display. The createEditor works ok with the QLineEdit().setAlignment(Qt.AlignRight).
Do I need to implement paint() for display of text?
PedanticHacker | 2021-04-05 09:15:33 UTC | #2
Maybe THIS will give you a hint.
Edward_Lipson | 2021-04-05 11:42:26 UTC | #3
I know that. If I use the QTableWidget (not my question here, I'm using QTableView/QAbstractTableModel with QStyledItemDelegate for editing) and set the QTableWidgetItem to the cell with setCellWidget, I can use the alignment of the QTableWidgetItem, along with a QValidator.
I'm trying to learn the Model/View concepts. I've got them working for what I need except for alignment.
PedanticHacker | 2021-04-05 11:49:23 UTC | #4
Can you try using
setTextAlignment() instead of
Edward_Lipson | 2021-04-05 13:01:58 UTC | #5
I kept on searching, and of course it was right in front of me (in the Book!) - Learpyqt qtableview modelview. It is part of the model, data() function .... elif role == Qt.TextAlignmentRole: if index.column() in (amt_columns): return Qt.AlignRight
For some reason it does not work correctly if I return Qt.AlignRight | Qt.AlighVCenter
Edited: read further on the page and saw Qt.AlignVCenter + Qt.AlignRight But: TypeError: unsupported operand type(s) for +: 'PySide2.QtCore.Qt.AlignmentFlag' and 'PySide2.QtCore.Qt.AlignmentFlag'