Results 1 to 6 of 6

Thread: QTextEdit and delayed image loading

  1. #1
    Join Date
    Jan 2007
    Posts
    45
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QTextEdit and delayed image loading

    Hello All !

    I'm using QTextEdit to display local text with embedded images from the internet. In the constructor I'm setting the text using setHtml(), and then I'm calling textEdit->document()->addResource() when each image arrives. After adding each image I want QTextEdit to immediately show it, the only way I've found to do it is to call textEdit->setHtml(textEdit->toHtml()), but this is really slow and causes flicker. Are there any better ways to do it ?

  2. #2
    Join Date
    May 2006
    Location
    Germany
    Posts
    108
    Thanks
    2
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit and delayed image loading

    I guess you could write a proxy-class which downloads the images and displays them once they were loaded. This would allow you to cache the images and prevent them from reloading all the time. Even though I don't know if Qt might do it that way already...
    "If you lie to the compiler, it will get its revenge." - Henry Spencer

  3. #3
    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: QTextEdit and delayed image loading

    Maybe QTextDocument::loadResource() would do the trick? Requires subclassing, though. At least worth trying.
    J-P Nurmi

  4. #4
    Join Date
    Jan 2007
    Posts
    45
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTextEdit and delayed image loading

    Thanks, I've tried it. But QTextEdit requests resource immediately after I'm setting the text. What I want is the ability to add image later (when it arrives from the server) and to get this image correctly displayed in QTextEdit without re-rendering the whole page. If I'm returning empty QVariant() from loadResource() while the image is still not available then when the image finally arrives it does not become visible in QTextEdit, or (if I resize the window) becomes incorrectly positioned.

  5. #5
    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: QTextEdit and delayed image loading

    Quote Originally Posted by Vladimir View Post
    Thanks, I've tried it. But QTextEdit requests resource immediately after I'm setting the text. What I want is the ability to add image later (when it arrives from the server) and to get this image correctly displayed in QTextEdit without re-rendering the whole page. If I'm returning empty QVariant() from loadResource() while the image is still not available then when the image finally arrives it does not become visible in QTextEdit, or (if I resize the window) becomes incorrectly positioned.
    Yes, I understood the problem, but that's not exactly what I meant with using QTextDocument::loadResource(). What I meant was using the built-in QTextDocument::loadResource() after the image has been received. It should load up the resource just fine.

    The only problem is updating the document layout. Basically we want QTextEditPrivate::relayoutDocument() to somehow get called. I'm quite surprised there is no direct way to do this. I would have expected to find something relevant in QAbstractTextDocumentLayout. I have found a hackish way to trigger update indirectly, by using QTextEdit::setLineWrapColumnOrWidth(). I'm not sure if it's that good idea relying on that because it might be a subject of change, but I have still attached an example of how to get it working for now.

    Unless someone is able to come up with a proper way of updating the document layout, I'd suggest reporting a suggestion to the Task-Tracker.
    Attached Files Attached Files
    J-P Nurmi

  6. The following 2 users say thank you to jpn for this useful post:

    saa7_go (16th July 2011), Vladimir (27th April 2007)

  7. #6
    Join Date
    Jan 2007
    Posts
    45
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTextEdit and delayed image loading

    Thanks a lot, your solution works ! If nobody will propose more direct solution I'll report this to the tracker.

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.