Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. TextArea with RichText, images only showing after a delayed interaction
Qt 6.11 is out! See what's new in the release blog

TextArea with RichText, images only showing after a delayed interaction

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 694 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marenz
    wrote on last edited by
    #1

    Hello,

    I am using a QML TextArea that is set to RichText. I am loading the content for text asynchronously from a website and assign the content of the site to the RichText. The site is quite simple with mostly image and p tags.

    The problem now is that images won't show until you do some kind of interaction, like clicking, selecting, scrolling. Maybe it's because they are external links or something. My current hack to fix it is to start a timer after I assigned the text and do a select(0,0) after 1 second or so. But if it is indeed the delay of the image loading, this probably will not work for slow network connections..

    Below you find the code I use:

    @
    Rectangle
    {
    id: newsRect

                Component
                {
                    id: newsTextComponent
    
                    TextArea
                    {
                        anchors.fill: parent
                        textFormat: TextEdit.RichText
                        readOnly: true
    
                        onLinkActivated:
                        {
                            Qt.openUrlExternally(link);
                        }
    
                    }
                }
    
    
                Component.onCompleted:
                {
                    var doc = new XMLHttpRequest();
                    doc.onreadystatechange = function() {
                        if (doc.readyState == XMLHttpRequest.DONE)
                        {
                            var comp = newsTextComponent.createObject(newsRect,
                                            {"text": doc.responseText});
                        }
                    }
                    var url = "http://<censored>";
    
                    doc.open("get", url);
                    doc.setRequestHeader("Content-Encoding", "UTF-8");
                    doc.send();
                }
    
                border.width: 1
            }
    

    @

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved