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. C++ widget in PySide6 application
Qt 6.11 is out! See what's new in the release blog

C++ widget in PySide6 application

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 3 Posters 2.0k Views 1 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.
  • D Offline
    D Offline
    dmytro-16384
    wrote on last edited by
    #1

    It looks like my PySide6 application is somewhat slow in drawing so I am considering moving my problematic Qt widget to the C++ python extension.

    It should definitely be possible because entire C++ Qt is available for Python :)

    But is this supported or recommended for custom widgets?

    Thanks!

    JonBJ 1 Reply Last reply
    0
    • F Offline
      F Offline
      friedemannkleint
      wrote on last edited by
      #4

      Are you using OpenGL or QPainter-based drawing?

      For example, there is QPainter.drawPointsNp() which takes 2 numpy-arrays:

      https://doc.qt.io/qtforpython-6/PySide6/QtGui/QPainter.html#PySide6.QtGui.PySide6.QtGui.QPainter.drawPointsNp

      For OpenGL, the QOpenGLFunctions typically also take numpy arrays.

      Nevertheless, creating Python bindings for a Custom widget is also possible with shiboken. It just takes some thought on how to structure it. You might want a C++ library containing the widget, a separate Qt Designer plugin and the bindings.

      For generating bindings. see for example
      https://doc.qt.io/qtforpython-6/examples/example_scriptableapplication__scriptableapplication.html

      D 1 Reply Last reply
      0
      • D dmytro-16384

        It looks like my PySide6 application is somewhat slow in drawing so I am considering moving my problematic Qt widget to the C++ python extension.

        It should definitely be possible because entire C++ Qt is available for Python :)

        But is this supported or recommended for custom widgets?

        Thanks!

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

        @dmytro-16384
        Hello and welcome.

        PySide/PyQt are only wrappers around Qt code for Python. Are you sure your "slowness" is in the Python code rather than the time it takes to do whatever Qt drawing or even your algorithm?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dmytro-16384
          wrote on last edited by
          #3

          @JonB said in C++ widget in PySide6 application:

          PySide/PyQt are only wrappers around Qt code for Python. Are you sure your "slowness" is in the Python code rather than the time it takes to do whatever Qt drawing or even your algorithm?

          I think slowness is in my python draw code. I'm drawing a lot (1000s) of small lines and preparing QPoints lists seems takes some time in Python. I tried obvious optimisations like re-using point objects and had some improvements but anyway it takes up to 100ms to update a frame.

          Drawing itself should be quite cheap if I understand correctly, it should directly be mapped to the Open GL draw call.

          So the next thing I want to try is moving this code to C++ if possible.

          Thanks!

          1 Reply Last reply
          1
          • F Offline
            F Offline
            friedemannkleint
            wrote on last edited by
            #4

            Are you using OpenGL or QPainter-based drawing?

            For example, there is QPainter.drawPointsNp() which takes 2 numpy-arrays:

            https://doc.qt.io/qtforpython-6/PySide6/QtGui/QPainter.html#PySide6.QtGui.PySide6.QtGui.QPainter.drawPointsNp

            For OpenGL, the QOpenGLFunctions typically also take numpy arrays.

            Nevertheless, creating Python bindings for a Custom widget is also possible with shiboken. It just takes some thought on how to structure it. You might want a C++ library containing the widget, a separate Qt Designer plugin and the bindings.

            For generating bindings. see for example
            https://doc.qt.io/qtforpython-6/examples/example_scriptableapplication__scriptableapplication.html

            D 1 Reply Last reply
            0
            • F friedemannkleint

              Are you using OpenGL or QPainter-based drawing?

              For example, there is QPainter.drawPointsNp() which takes 2 numpy-arrays:

              https://doc.qt.io/qtforpython-6/PySide6/QtGui/QPainter.html#PySide6.QtGui.PySide6.QtGui.QPainter.drawPointsNp

              For OpenGL, the QOpenGLFunctions typically also take numpy arrays.

              Nevertheless, creating Python bindings for a Custom widget is also possible with shiboken. It just takes some thought on how to structure it. You might want a C++ library containing the widget, a separate Qt Designer plugin and the bindings.

              For generating bindings. see for example
              https://doc.qt.io/qtforpython-6/examples/example_scriptableapplication__scriptableapplication.html

              D Offline
              D Offline
              dmytro-16384
              wrote on last edited by
              #5

              @friedemannkleint said in C++ widget in PySide6 application:

              QPainter.drawPointsNp

              Thank you for your hints. The QPainter.drawPointsNp looked promising, but I need lines :) I even constructed a hack using QXYSeries which also accepts Numpy arrays and can return QPoints, but unfortunately prebuilt PySide6 comes without any Numpy support (why???). Rebuilding PySide and support custom version looks like an overkill for me for now.

              I'm really appreciate your help, thank you for the links I will give them a try.

              F 1 Reply Last reply
              0
              • D dmytro-16384

                @friedemannkleint said in C++ widget in PySide6 application:

                QPainter.drawPointsNp

                Thank you for your hints. The QPainter.drawPointsNp looked promising, but I need lines :) I even constructed a hack using QXYSeries which also accepts Numpy arrays and can return QPoints, but unfortunately prebuilt PySide6 comes without any Numpy support (why???). Rebuilding PySide and support custom version looks like an overkill for me for now.

                I'm really appreciate your help, thank you for the links I will give them a try.

                F Offline
                F Offline
                friedemannkleint
                wrote on last edited by
                #6

                @dmytro-16384 PySide 6.4 will have numpy support built-in.

                1 Reply Last reply
                1

                • Login

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