Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Displaying a Large PDF without Freezing the UI Thread

Displaying a Large PDF without Freezing the UI Thread

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 202 Views
  • 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.
  • Serhan KarsS Offline
    Serhan KarsS Offline
    Serhan Kars
    wrote on last edited by Serhan Kars
    #1

    Hi everyone,

    I am having some problems displaying a large PDF file using a Loader. I have a sample code below:

    When the Load button is pressed in the code below, a large PDF file is displayed using PdfMultiPageView. I also make an AnimatedImage visible when the Loader is loading the component. However, since the PDF is a large file, the UI thread probably freezes when creating the PDF elements.

    Do you have any suggestions for cases like this?

    I am aware that using Qt.callLater is useful for operations with loops that take a long time, but this case is a little bit different.

    Thanks in advance.

    import QtQuick
    import QtQuick.Pdf
    import QtQuick.Controls
    
    Window {
        width: 500
        height: 500
    
        visible: true
        title: "PdfTest"
    
        Rectangle {
            anchors.fill:parent
    
            Loader{
                id: loader
                anchors.fill: parent
                asynchronous: true
                sourceComponent: undefined
                onLoaded: loadingImg.visible = false
            }
    
            Component{
                id: pmvComp
                PdfMultiPageView{
                    document: PdfDocument{ source: 'LARGE_PDF_FILE.pdf'} // some Pdf with 20 MB size
                }
            }
    
            AnimatedImage {
                id: loadingImg
                anchors.centerIn: parent
                source: "loading.gif"
                width:50
                height:50
                visible:false
            }
    
            Button{
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.bottom: parent.bottom
                anchors.bottomMargin: 10
    
                text: loader.sourceComponent == undefined ?  "Load":"Unload"
                onClicked: {
    
                        if(loader.sourceComponent == undefined){
                            loadingImg.visible = true
                            loader.sourceComponent = pmvComp
                        }
                        else{
                            loader.sourceComponent = undefined
                        }
                }
            }
        }
    
    }
    
    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