Results 1 to 6 of 6

Thread: QTextEdit align

  1. #1
    Join Date
    Sep 2009
    Location
    Warsaw/Poland
    Posts
    56
    Thanks
    8
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTextEdit align

    Hello,

    I have QTextEdit with:
    Qt Code:
    1. mainTextEdit->append(strContent);
    2.  
    3. // align
    4. if (strAlign == "center")
    5. mainTextEdit->setAlignment(Qt::AlignCenter);
    6. else
    7. mainTextEdit->setAlignment(Qt::AlignLeft);
    To copy to clipboard, switch view to plain text mode 

    and everythink is ok,
    but if I select by mouse text with align center and I add next text - text aligned center will be aligned left ....

    (Qt::AlignCenter | Qt::AlignAbsolute) is not working..

    setAligment should work only to last block not to text selected by mouse ...
    any suggestion ?

  2. #2
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit align

    hi,
    i hav tried with a similar example, the alignments are working fine.
    setAligment should work only to last block not to text selected by mouse
    for me , with mouse selection of text blocks, the alignment is still in centre only.

    bala

  3. #3
    Join Date
    Sep 2009
    Location
    Warsaw/Poland
    Posts
    56
    Thanks
    8
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit align

    Example of this strange bug:

    before.png
    after.png
    nienazwany.zip

  4. #4
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTextEdit align

    read documentation QTextEdit::setAlignment
    Sets the alignment of the current paragraph to a. Valid alignments are Qt::AlignLeft, Qt::AlignRight, Qt::AlignJustify and Qt::AlignCenter (which centers horizontally).
    Current paragraph is where cursor is. By default when cursor is not set cursor is treated as set to end of document.
    append method ignores current cursor so you have incoherency in code.

  5. #5
    Join Date
    Sep 2009
    Location
    Warsaw/Poland
    Posts
    56
    Thanks
    8
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit align

    Quote Originally Posted by MarekR22 View Post
    so you have incoherency in code.
    any example how can i fix it?

  6. #6
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTextEdit align

    Go lower. Update content of QTextDocument (QTextEdit::document) using QTextCursor.

    Qt Code:
    1. QTextCursor cursor(ui->lineEdit->document());
    2. cursor.movePosition(QTextCursor::End);
    3.  
    4. cursor.insertBlock(textBlockFormatInUse);
    5. // OR
    6. // cursor.insertBlock();
    7. // cursor.mergeBlockFormat(alignBlockFormat);
    8.  
    9. cursor.insertText("New text to insert");
    To copy to clipboard, switch view to plain text mode 

  7. The following user says thank you to MarekR22 for this useful post:

    mero (30th March 2011)

Similar Threads

  1. QTabWidget align
    By AlexD in forum Qt Programming
    Replies: 6
    Last Post: 10th August 2012, 13:19
  2. Question about align
    By Archa4 in forum Newbie
    Replies: 4
    Last Post: 14th March 2011, 08:36
  3. QTextEdit align right.
    By bunjee in forum Qt Programming
    Replies: 6
    Last Post: 7th November 2009, 20:43
  4. QItemDelegate Align
    By aekilic in forum Qt Programming
    Replies: 43
    Last Post: 1st April 2009, 07:52
  5. QTextEdit Justify align making work
    By dec0ding in forum Qt Programming
    Replies: 2
    Last Post: 13th January 2006, 12:02

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.