"ValueError: 'PySide6.QtGui.QPainter.drawText' called with wrong argument values" even though the arguments seem right
-
MRE:
from PySide6 import QtWidgets as qtw from PySide6 import QtGui as qtg from PySide6 import QtCore as qtc class Delegate(qtw.QAbstractItemDelegate): def paint(self, painter, option, index): text = index.model().data( index, qtc.Qt.ItemDataRole.DisplayRole ) text_rect = qtc.QRect( option.rect.left(), option.rect.top(), option.rect.width(), 200 ) painter.drawText(text_rect, 0, text, text_rect) def sizeHint(self, option, index): return qtc.QSize(200, 200) class Model(qtc.QAbstractListModel): def __init__(self) -> None: super().__init__() self._texts = ["text" for _ in range(10)] def rowCount(self, _) -> int: return 10 def data(self, index, role): if not index.isValid(): return None if role == qtc.Qt.ItemDataRole.DisplayRole: return self._texts[index.row()] return None class MainWindow(qtw.QMainWindow): def __init__(self): super().__init__() delegate = Delegate(self) self._model = Model() self._view = qtw.QListView(self) self._view.setModel(self._model) self._view.setItemDelegate(delegate) self.setCentralWidget(self._view) self.show() app = qtw.QApplication() mw = MainWindow() app.exec()
Error:
ValueError: 'PySide6.QtGui.QPainter.drawText' called with wrong argument values: PySide6.QtGui.QPainter.drawText(PySide6.QtCore.QRect(230, 10, 0, 200), 0, '', PySide6.QtCore.QRect(230, 10, 0, 200)) Found signature: PySide6.QtGui.QPainter.drawText(PySide6.QtCore.QRect, int, str, PySide6.QtCore.QRect)
One of the signatures I get on VSCode for
painter.drawText
:def drawText(r: PySide6.QtCore.QRect, flags: int, text: str, br: PySide6.QtCore.QRect) -> None
The provided signatures and the passed arguments match, don't they? Could this be a bug in PySide6?
The code causing the error is in thepaint
method in theDelegate
class. -
@Opara said in "ValueError: 'PySide6.QtGui.QPainter.drawText' called with wrong argument values" even though the arguments seem right:
PySide6.QtGui.QPainter.drawText(PySide6.QtCore.QRect, int, str, PySide6.QtCore.QRect)
I don't actually see this on page https://doc.qt.io/qtforpython/PySide6/QtGui/QPainter.html. [Actually I do find it, but it is mis-documented!] Does it make any difference if you remove the second
QRect
parameter? -
[Actually I do find it, but it is mis-documented!]
Now that you mention it, the documentation for that
drawText
function does mention aboundingRect
parameter but the function definition doesn't have it. Looks like the documentation might have just been copied from https://doc.qt.io/qt-6/qpainter.html#drawText-3 without any changes made, apart from the code.Does it make any difference if you remove the second
QRect
parameter?It works as one would expect with the second
QRect
removed. -
You can remove the last argument, and the code will work, but as Jon was mentioning, better to open a bug report. Can you please submit an issue into https://bugreports.qt.io/projects/PYSIDE with the same code? I think the problem lies in the signature selection, because we do apply some magic on top to use
drawText
with that signature and the optional argument:<modify-function signature="drawText(QRect,int,QString,QRect*)"> <modify-argument index="4"> <remove-argument/> <remove-default-expression/> </modify-argument> <modify-argument index="return"> <replace-type modified-type="QRect"/> </modify-argument> <inject-code class="target" position="beginning"> <insert-template name="fix_args,QRect*"/> </inject-code> </modify-function>