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

Unable to use QStyleOption due to missing casts

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 6.7.0
    • 6.3.0
    • PySide
    • None
    • de5f162a70 (pyside/pyside-setup/dev) 4eb0c8147b (pyside/pyside-setup/6.3) 4eb0c8147b (pyside/pyside-setup/wip/6.3_pypy) 4eb0c8147b (pyside/tqtc-pyside-setup/6.3) de5f162a70 (pyside/tqtc-pyside-setup/dev), d9f3fb812 (dev), ceae763ac (6.6)

    Description

      Similar to what's been reported in PYSIDE-220, this snippet:

      from PySide6.QtWidgets import QApplication, QCommonStyle, QStyle, QStyleFactory, QPushButton
      
      
      class Style(QCommonStyle):
      
          def drawControl(self, element, option, painter, widget=None):
              print(option)
              print(type(option))
              print(option.text)
      
      
      app = QApplication([])
      style = Style()
      
      w = QPushButton()
      w.setText("Hello World")
      w.setStyle(style)
      w.show()
      
      app.exec()
      

      results in:

      <PySide6.QtWidgets. at 0x7f96b7d50100>    # huh, that __repr__ seems like another bug?
      <class 'PySide6.QtWidgets.QStyleOption'>
      Traceback (most recent call last):
        File "/home/florian/proj/qutebrowser/git/style.py", line 9, in drawControl
          print(option.text)
      AttributeError: 'PySide6.QtWidgets.QStyleOption' object has no attribute 'text'
      

      but with PyQt6:

      <PyQt6.QtWidgets.QStyleOptionButton object at 0x7ff0d24ce6c0>
      <class 'PyQt6.QtWidgets.QStyleOptionButton'>
      Hello World
      

      I tried making it work by "casting" myself via:

      option = shiboken6.wrapInstance(shiboken6.getCppPointer(option), QStyleOptionButton)
      

      but that gives me:

      NameError: Error evaluating `Shiboken.wrapInstance`: name 'Shiboken' is not defined
      

      which I have no idea how to interpret (I didn't use capitalized Shiboken at all?!). Will report this separately, however.

      As noted in PYSIDE-220, in C++ there would be qstyleoption_cast for this (docs), but I'd expect PySide to give me the properly cast object directly.

      Attachments

        1. pyside1909_diag.diff
          5 kB
        2. pyside1909.py
          0.7 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kleint Friedemann Kleint
            the compiler Florian Bruhin
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: