0

I have been trying to figure this out without any luck. I am populating a table widget, some of the cells will contain numbers and I want to right justify them. Below is a statement for populating the cell.

self.ui.lst_MigPhases.setItem(x, 3, QtWidgets.QTableWidgetItem(str(int(item[3]))))

What is the appropriate statement(s) to right justify the cell? The value being pulled from the database is a float.

Kardacian
  • 23
  • 2
  • 1
    use `it = QtWidgets.QTableWidgetItem(str(int(item[3])))` `it.setTextAlignment(QtCore.Qt.AlignRight)` `self.ui.lst_MigPhases.setItem(x, 3, it)` – eyllanesc Jun 16 '20 at 00:12
  • Bingo thats it, I just figured it out my self 5 minutes ago. I was going on the assumption that the cell needed to be set to Right Justify. That is incorrect, you have to define a table item and set the value of the item. The set the alignment of the item. Finally set the value of the cell to the contents of the Item. Just as your solution shows. Thank you for confirming the answer. This was a pain to discover. – Kardacian Jun 17 '20 at 01:16

0 Answers0