PDA

View Full Version : Center HTML text in QTextTable



Melkorniano
27th November 2017, 11:35
I'm trying to make a header for a QTextTable. Everything is ok, except that I can't center the text inside the cell.

I've tried with "styles" trying to center the text (for example "style='text-align:center'"), but doesn't work.

I'm using HTML because I need to make several subscripts that I can't make with normal text.

How can I center the text? Any ideas?

Thanks!

high_flyer
27th November 2017, 12:08
The documentation is your friend.
http://doc.qt.io/qt-5/qtexttableformat.html#setAlignment

Melkorniano
27th November 2017, 14:07
I know, but this set the alignment for the table itself. I need to align the text inside the cells.

I think I solved the problem using:


cell_cursor = table.cellAt(i, j).firstCursorPosition()
cell_cursor.setBlockFormat(centerFormat)

Where:


centerFormat = QTextBlockFormat()
centerFormat.setAlignment(Qt.AlignCenter)

I'm using PyQt.