I am developing an application in Qt with Quick and some QML.
I need to interact with the contents of a pdf file opened inside of QPdfMultipageView. More specifically, I need the text to be selectable with mouse. Currently, there is no clear example in Qt documentation of how to achieve this with an already pre-defined view, such as PdfMultipageView.
ApplicationWindow {
id: root
width: 800
height: 1024
color: "darkgrey"
title: doc.title
visible: true
property string source // for main.cpp
PdfMultiPageView {
id: view
anchors.fill: parent
anchors.leftMargin: sidebar.position * sidebar.width
document: doc
searchString: searchField.text
onCurrentPageChanged: currentPageSB.value = view.currentPage + 1
}
PdfDocument {
id: doc
source: Qt.resolvedUrl(root.source)
onPasswordRequired: passwordDialog.open()
}
PdfSelection {
id: selection
document: doc
from: textSelectionDrag.centroid.pressPosition
to: textSelectionDrag.centroid.position
hold: !textSelectionDrag.active
}
Shape {
ShapePath {
PathMultiline {
paths: selection.geometry
}
}
}
DragHandler {
id: textSelectionDrag
acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
target: null
}
In docs, under the PdfSelection type description, there is an example, but it does not include view, only the document. In my case, PdfMultipageView handles the input in first place, hence not letting it pass to the DragHandler, which, in turn, should handle and update text selection. Also, there is no property in the view related to its ability to handle input, so I cannot tell it to not handle the input – it is always interactive and I cannot change this.
Any help would be greatly appreciated.