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. QSGGeometry does not work on PySide2

QSGGeometry does not work on PySide2

Scheduled Pinned Locked Moved Unsolved Qt for Python
16 Posts 5 Posters 2.1k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #7

    Did you open an issue on the bug tracker ?

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

    A 1 Reply Last reply
    0
    • SGaistS SGaist

      Did you open an issue on the bug tracker ?

      A Offline
      A Offline
      Advig
      wrote on last edited by
      #8

      @SGaist . Thanks. Yes. PYSIDE-1345

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

        Thank you !

        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
        • A Offline
          A Offline
          Advig
          wrote on last edited by
          #10

          @SGaist : Do you know any easy way I could write a patch for this. I am not sure if I will get a solution soon from bug tracking system.

          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            Yossip
            wrote on last edited by
            #11

            I am facing the same issue. This basically makes writing custom QQuickItems in Python impossible.

            Also, I am hitting this issue with PySide6.

            The bug that was reported is stuck nowhere.

            1 Reply Last reply
            0
            • Y Offline
              Y Offline
              Yossip
              wrote on last edited by
              #12

              Quick update. I reviewed the ticket again and realized there is a patch there. I recomplied PySide6 with the patch applied and I can say that vertexDataAsPoint2D() now does return a list of Point2D instead of just Point2D. In the ticket the developer states that the fix crashes submitted example. I am yet to confirm whether this causes any issues on my side.

              1 Reply Last reply
              0
              • Y Offline
                Y Offline
                Yossip
                wrote on last edited by
                #13

                Ok, I have the same problem as mentioned in the ticket - it segfaults.

                To summarize, you cannot write custom QQuickItems in Python at this time.

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

                  Thanks for the feedback !

                  Can you upload your minimal example on the report ?
                  It can help fix this issue as well.

                  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
                  • Y Offline
                    Y Offline
                    Yossip1
                    wrote on last edited by
                    #15

                    Hi SGaist,

                    Here's the code. It's really basic:

                    # This Python file uses the following encoding: utf-8
                    import os
                    from pathlib import Path
                    import sys
                    
                    from PySide6.QtGui import QGuiApplication, QColor
                    from PySide6.QtQml import QQmlApplicationEngine, qmlRegisterType
                    from PySide6.QtQuick import QQuickItem, QSGGeometryNode, QSGGeometry, QSGFlatColorMaterial, QSGNode
                    
                    
                    class JustItem(QQuickItem):
                        def __init__(self, parent=None):
                            super().__init__(parent)
                            self.setFlag(QQuickItem.ItemHasContents, enabled=True)
                    
                    
                        def updatePaintNode(self, node, update_data):
                            if node is None:
                                node = QSGGeometryNode()
                                geometry = QSGGeometry(QSGGeometry.defaultAttributes_Point2D(), 4)
                                geometry.setLineWidth(1)
                                geometry.setDrawingMode(QSGGeometry.DrawTriangles)
                    
                    
                                material = QSGFlatColorMaterial()
                                material.setColor(QColor(255, 0, 0, 127))
                    
                                node.setGeometry(geometry)
                                node.setMaterial(material)
                                node.setFlag(QSGNode.OwnsGeometry)
                                node.setFlag(QSGNode.OwnsMaterial)
                            else:
                                geometry = node
                    
                            vertex_data = geometry.vertexDataAsPoint2D()
                    
                            vertex_data[0].set(10, 10)
                            vertex_data[1].set(100, 10)
                            vertex_data[2].set(100, 100)
                            vertex_data[3].set(10, 100)
                            node.markDirty(QSGNode.DirtyGeometry)
                    
                            return node
                    
                    
                    if __name__ == "__main__":
                        qmlRegisterType(JustItem, "PythonTypes", 1, 0, "JustItem")
                    
                        app = QGuiApplication(sys.argv)
                        engine = QQmlApplicationEngine()
                        engine.load(os.fspath(Path(__file__).resolve().parent / "main.qml"))
                    
                    
                        if not engine.rootObjects():
                            sys.exit(-1)
                        sys.exit(app.exec())
                    

                    and main.qml:

                    import QtQuick
                    import QtQuick.Window
                    import PythonTypes 1.0
                    
                    Window {
                        width: 640
                        height: 480
                        visible: true
                        title: qsTr("Hello World")
                    
                        JustItem {
                    
                        }
                    }
                    

                    If you run it without the patch, it will complain that Point2D is not subscriptible (because Point2D and not a list of Point2Ds is returned). If you run it with the patch applied, it will segfault.

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

                      Thanks for posting it here but you should add it to the bug report as well. It will be easier to find over there.

                      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

                      • Login

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