TextArea with RichText, images only showing after a delayed interaction



  • 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
            }
    

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.