Results 1 to 3 of 3

Thread: Insert image in RTL QTextEdit problem!

  1. #1
    Join Date
    Nov 2006
    Location
    Saudi Arabia
    Posts
    18
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Insert image in RTL QTextEdit problem!

    Hello,

    I have a problem in inserting image in RightToLeft QTextEdit.
    What i want is to insert some text then insert image.

    I try the following code:
    Qt Code:
    1. QTextEdit* textEdit = new QTextEdit;
    2.  
    3. QTextOption option=textEdit->document()->defaultTextOption();
    4. option.setTextDirection(Qt::RightToLeft); // RTL.
    5. textEdit->document()->setDefaultTextOption(option);
    6.  
    7. QTextCursor cursor = textEdit->textCursor();
    8.  
    9. cursor.insertText("مرحبا بكم في كيوتي العربي"); // insert Arabic text
    10.  
    11. QTextImageFormat imageFormat;
    12. imageFormat.setName(":/images/jumpy.gif");
    13. cursor.insertImage(imageFormat); // then insert the Image.
    14.  
    15. textEdit->show();
    To copy to clipboard, switch view to plain text mode 


    The problem is the image appear in the wrong location, it should appear after the text not before it!

    How i can solve it ?

    I also try to change the current block format direction but it did not solve the problem.

    Thanks in advance.
    Attached Images Attached Images

  2. #2
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Thanks
    20
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Insert image in RTL QTextEdit problem!

    For some characters, Qt inserts it in left to right mode even when you have set it to RTL. For e.g. if you enter a space or 1 digit number it's inserted in the left to right manner. So, i guess when you try to insert the image, somehow it doesn't insert it in RTL format. Simplest solution will be to manually set the cursor in the end and try. Although i am sure there should be a better solution to it, maybe somebody else can help you with this.

    I am also trying to have a QTextEdit where user can mix english and arabic characters. But in my case if you type arabic, the text is not aligned to the right as per your screenshot although text is properly typed right to left. Is it normal? It aligns correctly when QTextEdit::setAlignment(Qt::AlignRight) is used.
    Last edited by montylee; 23rd October 2009 at 22:54.

  3. #3
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Thanks
    20
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Insert image in RTL QTextEdit problem!

    Ok, if you add this line before cursor.insertImage(), it should work:

    Qt Code:
    1. cursor.movePosition(QTextCursor::Start);
    To copy to clipboard, switch view to plain text mode 

    Although, there might be a better and more logical solution to this. Please let me know how you managed to get the arabic text right aligned.

Similar Threads

  1. [Qt4.1] How to insert an image inside a Form?
    By Gonzalez in forum Qt Tools
    Replies: 5
    Last Post: 23rd September 2008, 11:20
  2. Transfer image problem
    By probine in forum Qt Programming
    Replies: 7
    Last Post: 4th May 2006, 10:24
  3. problem with the back ground image
    By Seema Rao in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2006, 21:34
  4. problem with image colections
    By zlatko in forum Qt Programming
    Replies: 1
    Last Post: 6th February 2006, 13:43
  5. Problem with inserting text into QTextEdit
    By xorrr in forum Qt Programming
    Replies: 0
    Last Post: 6th February 2006, 11:45

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.