Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QStyleOptionViewItem.rect
Forum Updated to NodeBB v4.3 + New Features

QStyleOptionViewItem.rect

Scheduled Pinned Locked Moved Solved Qt for Python
9 Posts 4 Posters 864 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MasterQM Offline
    MasterQM Offline
    MasterQ
    wrote on last edited by
    #1

    Hello from a Python beginner,

    I have to subclass QStyledItemDelegate. In method updateEditorGeometry the following code is marked

        def updateEditorGeometry(self, editor: QWidget, option: QStyleOptionViewItem, index: QModelIndex):
            rect = option.rect() # <- IDE is claiming rect() is no method of QStyleOptionViewItem
            rect.setWidth(option.rect().width + 100)
            editor.setGeometry(rect)
    

    According to my IDE (PyCharm) the class QStyleOptionViewItem has (in Python) no method rect(). That's "true" since rect() is a method of its super class QStyleOption .

    How to access rect() (or is it rec?) from QStyleOptionViewItem?

    J.

    BTW:

    the C++ pendant is working:

        void CategoryDelegate::updateEditorGeometry(QWidget *editor,
                                                           const QStyleOptionViewItem &option,
                                                           const QModelIndex &index) const {
            auto rect = option.rect;
            rect.setWidth(option.rect.width() + 100);
            editor->setGeometry(rect);
    
    1 Reply Last reply
    0
    • MasterQM MasterQ

      no, there is really no rect, see the documentation of PySide I provided. The IDE is right!

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #8

      @MasterQ said in QStyleOptionViewItem.rect:

      no, there is really no rect, see the documentation of PySide I provided. The IDE is right!

      No, there is indeed a rect member!

      • I agree under PySide6, however it is implemented, IDEs do not see QStyleOptionViewItem.rect nor the QStyleOption.rect which is what it is (inherited). Something to do with shiboken I think. Tested under PyCharm, the only/best IDE I trust.

      • However whatever the IDE says the PySide6 code with option.rect does work at runtime, and accesses the rect.

      • Under PyQt6 (in PyCharm) the IDE does find QStyleOptionViewItem.rect. And it's in __PyQt6_sip.simplewrapper, which is PyQt only.

      So the IDE problem is PySide only, and will have something to do with its implementation there (e.g. not being constructed till runtime, which I found with something else recently where IDE could not find a symbol). [Oh yes, that is the implementation of PySide still supporting all the old enums, Qt.AlightLeft, where you should now use the new ones, Qt.AllignFlag.AlignLeft. PySide6 creates the former "aliases" dynamically at runtime, so they work but the IDE does not know that and says they don't exist.]

      @SGaist
      While runtime behaviour is fine this is a code-time "limitation" of PySide implementation. Whether that is a "bug" or (as I suspect) a "feature" of the PySide implementation, and hence not worth reporting, I do not know. There are other places in Python/PySide/PyQt where things get created at runtime and so are not visible at IDE edit time as part of the implementation.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        The hint is correct. rect is not a method it's a public variable. Just use it directly.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • MasterQM Offline
          MasterQM Offline
          MasterQ
          wrote on last edited by
          #3

          neither rect nor rect() is recognized

          a30e0ac5-b173-4a63-a7fb-312f6ed4bc2a-grafik.png

          8abb994b-c15a-427b-a107-6f61e9dd4ffb-grafik.png

          see documentation:

          class QStyleOptionViewItem

          and

          class QStyleOption

          this mechanism of PySide seems significantly different to that of C++. Since the PySide documentation seems to be a robot translation from C++, it is not really helpfull.

          I don't get it, how PySide is working here.

          jsulmJ 1 Reply Last reply
          0
          • MasterQM Offline
            MasterQM Offline
            MasterQ
            wrote on last edited by
            #4

            Maybe this way?

                def updateEditorGeometry(self, editor: QWidget, option: QStyleOptionViewItem, index: QModelIndex):
                    g = editor.geometry()
                    g.setWidth(g.width() + 100)
                    editor.setGeometry(g)
            
            1 Reply Last reply
            0
            • MasterQM MasterQ

              neither rect nor rect() is recognized

              a30e0ac5-b173-4a63-a7fb-312f6ed4bc2a-grafik.png

              8abb994b-c15a-427b-a107-6f61e9dd4ffb-grafik.png

              see documentation:

              class QStyleOptionViewItem

              and

              class QStyleOption

              this mechanism of PySide seems significantly different to that of C++. Since the PySide documentation seems to be a robot translation from C++, it is not really helpfull.

              I don't get it, how PySide is working here.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #5

              @MasterQ said in QStyleOptionViewItem.rect:

              neither rect nor rect() is recognized

              But does it actually work when you run the application?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • MasterQM Offline
                MasterQM Offline
                MasterQ
                wrote on last edited by
                #6

                no, there is really no rect, see the documentation of PySide I provided. The IDE is right!

                JonBJ 1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  Can you provide a minimal runable script that shows this ?
                  Creating a QStyleOptionViewItem manually works.

                  >>> from PySide6.QtWidgets import QStyleOptionViewItem
                  >>> option = QStyleOptionViewItem()
                  >>> option.rect
                  PySide6.QtCore.QRect(0, 0, 0, 0)
                  >>>
                  

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • MasterQM MasterQ

                    no, there is really no rect, see the documentation of PySide I provided. The IDE is right!

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #8

                    @MasterQ said in QStyleOptionViewItem.rect:

                    no, there is really no rect, see the documentation of PySide I provided. The IDE is right!

                    No, there is indeed a rect member!

                    • I agree under PySide6, however it is implemented, IDEs do not see QStyleOptionViewItem.rect nor the QStyleOption.rect which is what it is (inherited). Something to do with shiboken I think. Tested under PyCharm, the only/best IDE I trust.

                    • However whatever the IDE says the PySide6 code with option.rect does work at runtime, and accesses the rect.

                    • Under PyQt6 (in PyCharm) the IDE does find QStyleOptionViewItem.rect. And it's in __PyQt6_sip.simplewrapper, which is PyQt only.

                    So the IDE problem is PySide only, and will have something to do with its implementation there (e.g. not being constructed till runtime, which I found with something else recently where IDE could not find a symbol). [Oh yes, that is the implementation of PySide still supporting all the old enums, Qt.AlightLeft, where you should now use the new ones, Qt.AllignFlag.AlignLeft. PySide6 creates the former "aliases" dynamically at runtime, so they work but the IDE does not know that and says they don't exist.]

                    @SGaist
                    While runtime behaviour is fine this is a code-time "limitation" of PySide implementation. Whether that is a "bug" or (as I suspect) a "feature" of the PySide implementation, and hence not worth reporting, I do not know. There are other places in Python/PySide/PyQt where things get created at runtime and so are not visible at IDE edit time as part of the implementation.

                    1 Reply Last reply
                    0
                    • MasterQM Offline
                      MasterQM Offline
                      MasterQ
                      wrote on last edited by
                      #9

                      @JonB said in QStyleOptionViewItem.rect:

                      @MasterQ said in QStyleOptionViewItem.rect:

                      no, there is really no rect, see the documentation of PySide I provided. The IDE is right!

                      No, there is indeed a rect member!

                      Thank you for that information.

                      My last tests confirm your answer, I was wrong about missing rect. Sry for the confusion.

                      1 Reply Last reply
                      0
                      • MasterQM MasterQ has marked this topic as solved on

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved