0

I am currently working with pyqt and have a table. In this table I want to center all the items both horizontally and vertically.

My code is:

for row_index in range(9):
    for column_index in range(9):
        item = self.ui.sudoku.item(row_index, column_index)
        item.setTextAlignment(QtCore.Qt.AlignHCenter)

I tried adding the line to center it vertically: for row_index in range(9):

for row_index in range(9):
    for column_index in range(9):
        item = self.ui.sudoku.item(row_index, column_index)
        item.setTextAlignment(QtCore.Qt.AlignHCenter)
        item.setTextAlignment(QtCore.Qt.AlignVCenter)

But now the text only aligns centered only vertically. How can I make the text align centered in both dimensions?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
SdahlSean
  • 573
  • 3
  • 13
  • I think you're looking for [`QtCore.Qt.AlignCenter`](https://doc.qt.io/qt-5/qt.html#AlignmentFlag-enum). – G.M. Apr 13 '19 at 19:47
  • use `item.setTextAlignment(QtCore.Qt.AlignCenter)` or `item.setTextAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)` – eyllanesc Apr 13 '19 at 21:08

0 Answers0