Details
-
Bug
-
Resolution: Incomplete
-
Not Evaluated
-
None
-
5.14.0
-
None
Description
If I use QAbstractTextDocumentLayout.PaintContext.selections in draw Method,
this error occurs.
>PySide1.2.1 documentation says as follows.
The QAbstractTextDocumentLayout.PaintContext class is a convenience class defining the parameters used when painting a document’s layout.
A paint context is used when rendering custom layouts for QTextDocuments with the QAbstractTextDocumentLayout.draw() function. It is specified by a cursor position , default text color , clip rectangle and a collection of selections .
>Qt for Python(PySide2) documentation doesn't say anything.
But both version emit
#PySide AttributeError: 'PySide.QtGui.QAbstractTextDocumentLayout.PaintCont' object has no attribute 'selections' #PySide2 AttributeError: 'PySide2.QtGui.QAbstractTextDocumentLayout.PaintCon' object has no attribute 'selections'
There are two problems.
First, I think error message has a typo: 'PaintCont' or 'PaintCon'
Second: I think it doesn't exist originally, but QAbstractTextDocumentLayout.PaintContext has no attribute of selections.
According to woboq, this selections attribute is used in draw(painter, context) function.
https://code.woboq.org/qt5/qtbase/src/gui/text/qabstracttextdocumentlayout.h.html
selections are used in actual code.
Is there somewhat bug?
It is very ambiguous but I came to have a doubt.
This attribute seems to be deleted without a special reason...( I don't know about it at all though)
>Update
import sys from PySide2 import QtWidgets, QtGui, QtCore import os import PySide2 dirname = os.path.dirname(PySide2.__file__) plugin_path = os.path.join(dirname, 'plugins', 'platforms') os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path class TextEdit(QtWidgets.QTextEdit): def __init__(self, parent=None): super(TextEdit, self).__init__(parent=None) self.document().setDocumentLayout(TextDocumentLayout(self.document())) class TextDocumentLayout(QtGui.QAbstractTextDocumentLayout): def __init__(self, doc): super(TextDocumentLayout, self).__init__(doc) def draw(self, painter, context): print(context.selections) pass def documentChanged(self, fr, charsRemoved, charsAdded): pass def hitTest(self, point, accuracy): return -1 def blockBoundingRect(self, block): return QtCore.QRectF() def frameBoundingRect(self, frame): return QtCore.QRectF() def pageCount(self): return 1 def documentSize(self): return QtCore.QSizeF(797, 1123) def main(): if QtWidgets.QApplication.instance() is not None: app = QtWidgets.QApplication.instance() else: app = QtWidgets.QApplication([]) widget = TextEdit() widget.show() sys.exit(app.exec_()) if __name__ == "__main__": main()