QPdfView how to select text by mouse
-
I can load and render a PDF file using QPdfView:
// inside MainWindow constructor QPdfView *pdf = new QPdfView(); pdf->setPageMode(QPdfView::PageMode::MultiPage); pdf->setZoomMode(QPdfView::ZoomMode::FitToWidth); setCentralWidget(pdf); QPdfDocument *doc = new QPdfDocument(this); pdf->setDocument(doc); doc->load("C:\\path\\to\\sample.pdf");How to make text selectable using mouse?
Do I need to convert mousePress/Move/Release position to pdf coordinate (and how)? And manually construct QPdfSelection object using start/end location?
-
I can load and render a PDF file using QPdfView:
// inside MainWindow constructor QPdfView *pdf = new QPdfView(); pdf->setPageMode(QPdfView::PageMode::MultiPage); pdf->setZoomMode(QPdfView::ZoomMode::FitToWidth); setCentralWidget(pdf); QPdfDocument *doc = new QPdfDocument(this); pdf->setDocument(doc); doc->load("C:\\path\\to\\sample.pdf");How to make text selectable using mouse?
Do I need to convert mousePress/Move/Release position to pdf coordinate (and how)? And manually construct QPdfSelection object using start/end location?
@songziming
GooglingQPdfView select textgives e.g. https://askubuntu.com/questions/1071771/where-is-the-text-selection-tool-in-qpdfview. And see https://forum.qt.io/topic/115458/how-can-i-select-and-copy-text-from-a-qpdfview-widget. -
@songziming
GooglingQPdfView select textgives e.g. https://askubuntu.com/questions/1071771/where-is-the-text-selection-tool-in-qpdfview. And see https://forum.qt.io/topic/115458/how-can-i-select-and-copy-text-from-a-qpdfview-widget. -
(disclaimer: I have not used either the standalone program nor the QPdfView class)
Although @JonB appears to have provided links that refer to the standalone utility viewer, said viewer is open source and built using Qt. Therefore, (if no better option or no quicker tip appears in this forum), we can probably find clues about how to achieve text selection by looking at the code for the standalone utility and learning how it achieves this.
Source code: https://git.launchpad.net/qpdfview
(Learning from source code of qpdfview utility may or may not have been what @JonB had in mind, but either way the point stands. I do apologize if I am appearing to just "copy" or "regurgitate" JonB's answer as my own.)