Results 1 to 3 of 3

Thread: Does QTextEdit have problem with combination of text direction and alignment?

  1. #1
    Join Date
    Dec 2008
    Location
    Isfahan (Iran)
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Does QTextEdit have problem with combination of text direction and alignment?

    hi freinds,

    I use a QTextEdit in my app, and want it to support both rtl & ltr text directions, while having ability to change alignment, independent of the text direction.

    I wrote these slots for setting alignment:
    Qt Code:
    1. void MyEditor::sltAlignRight()
    2. {
    3. editor->setAlignment(Qt::AlignRight);
    4. editor->setFocus(Qt::OtherFocusReason);
    5. }
    6.  
    7. void MyEditor::sltAlignLeft()
    8. {
    9. editor->setAlignment(Qt::AlignLeft);
    10. editor->setFocus(Qt::OtherFocusReason);
    11. }
    To copy to clipboard, switch view to plain text mode 

    and this one for changing text direction:
    Qt Code:
    1. void MyEditor::sltChangeLayoutDirection()
    2. {
    3. QTextBlockFormat f = editor->textCursor().blockFormat();
    4.  
    5. if (f.layoutDirection() != Qt::RightToLeft) {
    6. f.setLayoutDirection(Qt::RightToLeft);
    7. } else {
    8. f.setLayoutDirection(Qt::LeftToRight);
    9. }
    10. editor->textCursor().mergeBlockFormat(f);
    11.  
    12. editor->setFocus(Qt::OtherFocusReason);
    13. }
    To copy to clipboard, switch view to plain text mode 

    the problem is, when sltChangeLayoutDirection() is triggered, to make the text right-to-left, direction changes successfully, but editor content is aligned at right side.
    but editor->alignment() returns Qt::AlignLeft.
    now, if I call sltAlignRight(), editor content will be aligned at left side!

    I wonder if this is my fault in coding, or it's really a bug of QTextEdit?
    Did anyone have the same problem?

    I use ubuntu8.04 with kde4.1.
    thanks a lot.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Does QTextEdit have problem with combination of text direction and alignment?

    Just a wild guess, does it make any difference if you combine the alignment with Qt::AlignAbsolute?

    Qt Code:
    1. editor->setAlignment(Qt::AlignRight | Qt::AlignAbsolute);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    golnaz (30th December 2008)

  4. #3
    Join Date
    Dec 2008
    Location
    Isfahan (Iran)
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Solved: Does QTextEdit have problem with combination of text direction and alignment?

    thank you very much my friend, it works.

    you really helped me, thanks for your attention.

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.