Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1996

"ValueError: 'PySide6.QtGui.QPainter.drawText' called with wrong argument values" even though the arguments are correct

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3: Somewhat important
    • None
    • 6.3.0, 6.2.4, 6.3.1
    • PySide
    • None

    Description

      The

      QPainter().drawText()

      function with the following signature:

      painter.drawText(QRect, int, str, QRect)

      is not working as expected. It produces an error saying the arguments passed are incorrect even when the arguments passed are correct.

      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

      Qt6 documentation for the function signature: https://doc.qt.io/qt-6/qpainter.html#drawText-3

      While this specific signature for the function `drawText` is not properly documented in the documentation for PySide, there is a reference to this feature in the documentation for the `drawText`  that follows: https://doc.qt.io/qtforpython/PySide6/QtGui/QPainter.html#PySide6.QtGui.PySide6.QtGui.QPainter.drawText .

      QPainter::drawText(int x, int y, int width, int height, int flags, 
            const QString &text, QRect *boundingRect = nullptr);
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              shpremna Shyamnath Premnadh
              opara Opara Arapo
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes