0

With PySide6 getSelection returns an invalid QPdfSelection. No matter what arguments we pass to it.

We'd expect a valid QPdfSelection with a non-zero boundingRectangle.

How to reproduce it

We call getAllText on a given QPdfDocument and we get a valid QPdfSelection and its boundingRectangle as expected:

selection: QPdfSelection = document.getAllText(1)
print(selection.isValid(), selection.boundingRectangle())
# True PySide6.QtCore.QRectF(72.000000, 72.000000, 451.000000, 728.000000)

But when we call getSelection we get an invalid QPdfSelection with a zero-ed boundingRectangle. No matter what arguments we pass to it (see below).

In our example here we use the top_left and bottom_right QPointFs of the boundingRectangle of the QPdfSelection returned by getAllText above:

top_left: QPointF = selection.boundingRectangle().topLeft()
bottom_right: QPointF = selection.boundingRectangle().bottomRight()
selection: QPdfSelection = document.getSelection(current_page, top_left, bottom_right)
print(selection.isValid(), selection.boundingRectangle())
# False PySide6.QtCore.QRectF(0.000000, 0.000000, 0.000000, 0.000000)

Minimal Reproducible Example

pip install pyside6==6.9.2
from PySide6.QtCore import QPointF
from PySide6.QtPdf import QPdfDocument, QPdfSelection

document: QPdfDocument = QPdfDocument(None)
document.load("filename.pdf")
current_page: int = 1

print("# getAllText()")
selection: QPdfSelection = document.getAllText(current_page)
print(selection.isValid(), selection.boundingRectangle())
# returns as expected:
# True PySide6.QtCore.QRectF(72.000000, 72.000000, 451.000000, 728.000000)

top_left: QPointF = selection.boundingRectangle().topLeft()
bottom_right: QPointF = selection.boundingRectangle().bottomRight()
print(top_left)
# PySide6.QtCore.QPointF(72.000000, 72.000000)
print(bottom_right)
# PySide6.QtCore.QPointF(523.000000, 800.000000)

print("# getSelection()")
selection: QPdfSelection = document.getSelection(current_page, top_left, bottom_right)
print(selection.isValid(), selection.boundingRectangle())
# doesn't returns as expected:
# False PySide6.QtCore.QRectF(0.000000, 0.000000, 0.000000, 0.000000)

Tested on both Linux and Windows

  • Linux 5.10.0-19-amd64 #1 SMP Debian 5.10.149-1 (2022-10-17) with Python 3.12.11, Qt: v 6.9.2, PyQt: v 6.9.2
  • Linux Debian 12 6.1.0-22-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.94-1 (2024-06-21) with Python 3.11.2, Qt: v 6.9.2, PyQt: v 6.9.2
  • Windows 10 10.0.19045 with Python 3.12.6, Qt: v 6.9.2, PyQt: v 6.9.2

Both with following python packages

pyside6==6.9.2
pyside6-addons==6.9.2
pyside6-essentials==6.9.2
shiboken6==6.9.2
4
  • 1
    Please provide a proper minimal reproducible example, and state the specific versions of PySide6/Qt6 you are testing with, and on which platform. Commented Aug 28 at 10:31
  • This seems to have been raised before on the QT forum with no resolution forum.qt.io/topic/120120/text-selection-in-qpdfdocument Commented Aug 28 at 10:34
  • QTBUG-129615 was reported a few months ago, but the OP mentioned that reinstalling PySide solved the problem (it's unclear if they installed the same version). As written above, we need to know the actual Qt/OS version you're using, and if you also tried with a more recent version as well. Commented Aug 28 at 13:26
  • I can reproduce the problem on Linux using PySide6/Qt6 versions 6.5.2, 6.7.3, 6.8.2 and 6.9.2. A better way to analyse the problem is to use getSelectionAtIndex to create the bounding-rect, and then play around with the start-index and max-length. For certain start and end points, getSelection works as expected, but the behaviour can be very unpredictable. It seems that the underlying chrome pdf-engine doesn't always create the text-rects and map them to the view in the way it should. Commented Sep 1 at 12:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.