How to align text in QTextEdit

  • Hi,
    I want to align text present in QTextEdit.
    I tried some options present in net like " text-align:center" but they didn't work.

    Could you please help me on this...


  • Lifetime Qt Champion

    You can always just right click a TextEdit in Designer and use its Edit HTML editor.
    It allows you to do basic things and get the html.

    <html><head/><body><p align="center"><span style=" font-size:8.25pt;">CENTER</span></p></body></html>

    alt text

  • Moderators

    You can use setAlignment() method. Here's an example:

    QTextEdit te;
    te.append("This paragraph is left aligned");
    te.append("This paragraph is right aligned");

    or you can use html:

    QTextEdit te;
    te.setHtml("<p align=\"left\">This paragraph is left aligned"
               "<p align=\"right\">This paragraph is right aligned");

    or CSS:

    QTextEdit te;
    te.setHtml("<p style=\"text-align: left\">This paragraph is left aligned"
               "<p style=\"text-align: right\">This paragraph is right aligned");

  • @Chris-Kawa's working

  • @mrjj Thanks for providing solution....

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.