매번 찾아 보는게 귀찮어 필요한 내용은 정리해 둔다. 출처를 분명히 밝혀둔다.
table = QTableWidget(6,3)
table.setAlternatingRowColors(true)
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
for i=0 in range(table.rowCount()):
for j=0 in range(table->columnCount()):
item = QTableWidgetItem()
text = "({},{})".format(i).format(j)
item.setText(text)
item.setTextAlignment(Qt.AlignCenter)
table.setItem(i,j,item)
핵심은,
item.setTextAlignment(Qt.AlignCenter)
item.setTextAlignment(Qt.AlignVCenter | Qt.AlignRight) 가운데 오른쪽 정렬
이 옵션 값은 아래 페이지에도 확인할 수 있다.
https://doc.qt.io/qt-6/qt.html
The horizontal flags are:
ConstantValueDescription
Qt::AlignLeft | 0x0001 | Aligns with the left edge. |
Qt::AlignRight | 0x0002 | Aligns with the right edge. |
Qt::AlignHCenter | 0x0004 | Centers horizontally in the available space. |
Qt::AlignJustify | 0x0008 | Justifies the text in the available space. |
The vertical flags are:
ConstantValueDescription
Qt::AlignTop | 0x0020 | Aligns with the top. |
Qt::AlignBottom | 0x0040 | Aligns with the bottom. |
Qt::AlignVCenter | 0x0080 | Centers vertically in the available space. |
Qt::AlignBaseline | 0x0100 | Aligns with the baseline. |
Photo by Jose Mueses from Pexels: https://www.pexels.com/photo/photo-of-five-cars-parked-1280560/