Results 1 to 3 of 3

Thread: Center HTML text in QTextTable

  1. #1
    Join Date
    Nov 2017
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Center HTML text in QTextTable

    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Center HTML text in QTextTable

    The documentation is your friend.
    http://doc.qt.io/qt-5/qtexttableform...l#setAlignment
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Nov 2017
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Center HTML text in QTextTable

    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:

    Qt Code:
    1. cell_cursor = table.cellAt(i, j).firstCursorPosition()
    2. cell_cursor.setBlockFormat(centerFormat)
    To copy to clipboard, switch view to plain text mode 

    Where:
    Qt Code:
    1. centerFormat = QTextBlockFormat()
    2. centerFormat.setAlignment(Qt.AlignCenter)
    To copy to clipboard, switch view to plain text mode 

    I'm using PyQt.

Similar Threads

  1. Replies: 3
    Last Post: 19th January 2016, 18:22
  2. vertical text in a QTextTable
    By sipahi in forum Newbie
    Replies: 2
    Last Post: 6th February 2013, 22:40
  3. Replies: 0
    Last Post: 2nd August 2010, 10:37
  4. How to center text in a QTableView
    By dougbroadwell in forum Qt Programming
    Replies: 9
    Last Post: 26th March 2009, 12:17
  5. Center text on painter
    By masoroso in forum Newbie
    Replies: 5
    Last Post: 2nd May 2006, 15:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.