Results 1 to 3 of 3

Thread: Qt::AlignVCenter does not work on QTextTable

  1. #1
    Join Date
    Jan 2013
    Posts
    23
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Qt::AlignVCenter does not work on QTextTable

    I created QTextTable:

    Qt Code:
    1. QTextDocument *document=new QTextDocument(this);
    2. QTextCursor cursor(document);
    3. cursor.movePosition(QTextCursor::Start);
    4.  
    5. QTextTableCellFormat cellFormat;
    6. cellFormat.setLeftPadding(7);
    7. cellFormat.setRightPadding(7);
    8.  
    9. QBrush blackBrush(Qt::SolidPattern);
    10. QTextTableFormat tableFormat;
    11. tableFormat.setAlignment(Qt::AlignCenter);
    12. tableFormat.setBorderBrush(blackBrush);
    13. tableFormat.setBorder(0.5);
    14. tableFormat.setCellSpacing(0);
    15. tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
    16. tableFormat.setWidth(QTextLength(QTextLength::PercentageLength, 100));
    17. QTextTable *table = cursor.insertTable(10,10,tableFormat);
    18.  
    19. QTextBlockFormat centerAlignment;
    20. centerAlignment.setAlignment(Qt::AlignCenter);
    21.  
    22. table->mergeCells(0,0,10,5);
    23. cursor = table->cellAt(0, 0).firstCursorPosition();
    24. cursor.setBlockFormat(centerAlignment);
    25. cursor.insertText("text");
    To copy to clipboard, switch view to plain text mode 

    I want to write text in the middle of cell vertically and horizontally
    But my text is in the middle horizontally but it is not in the middle vertically.
    Also Qt::AlignVCenter and Qt::AlignBottom do not work.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Qt::AlignVCenter does not work on QTextTable

    Set the format on the cell object..
    Qt Code:
    1. QTextCharFormat format = table->cellAt(0, 0).format();
    2. format.setVerticalAlignment(QTextCharFormat::AlignMiddle);
    3. table->cellAt(0, 0).setFormat(format);
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jan 2013
    Posts
    23
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt::AlignVCenter does not work on QTextTable

    Thank you @Santosh Reddy
    Last edited by sipahi; 5th February 2013 at 22:28.

Similar Threads

  1. How we can set textcolor in a QTextTable.
    By rajeshclt3 in forum Qt Programming
    Replies: 2
    Last Post: 16th November 2010, 14:49
  2. QTextTable border
    By gigi in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2010, 13:11
  3. QTextTable is slow!
    By Ishmael in forum Newbie
    Replies: 6
    Last Post: 29th September 2009, 21:25
  4. qtexttable row's height
    By dreamer in forum Qt Programming
    Replies: 0
    Last Post: 12th June 2008, 16:26
  5. Help with QTextTable
    By fwohlfert in forum Newbie
    Replies: 1
    Last Post: 1st November 2006, 10:05

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.