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. How to add plugins to PySide6-designer?
Forum Updated to NodeBB v4.3 + New Features

How to add plugins to PySide6-designer?

Scheduled Pinned Locked Moved Solved Qt for Python
15 Posts 5 Posters 3.1k 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.
  • F Offline
    F Offline
    friedemannkleint
    wrote on last edited by friedemannkleint
    #2

    See https://doc.qt.io/qtforpython-6/tutorials/basictutorial/uifiles.html#designer-custom-widgets and the task menu example https://doc.qt.io/qtforpython-6/examples/example_designer_taskmenuextension.html

    Note you need to launch pyside6-designer for this to work.

    T 1 Reply Last reply
    0
    • F friedemannkleint

      See https://doc.qt.io/qtforpython-6/tutorials/basictutorial/uifiles.html#designer-custom-widgets and the task menu example https://doc.qt.io/qtforpython-6/examples/example_designer_taskmenuextension.html

      Note you need to launch pyside6-designer for this to work.

      T Offline
      T Offline
      Tim Tu
      wrote on last edited by Tim Tu
      #3

      @friedemannkleint Thanks! I have written the register.py, but now designer can't start. (Also, I have tried the example, it doesn't work too.)

      ❯ export PYSIDE_DESIGNER_PLUGINS="registertictactoe.py"
      ❯ pyside6-designer
      Traceback (most recent call last):
        File "/home/tim/mambaforge/envs/aligner/bin/pyside6-designer", line 8, in <module>
          sys.exit(designer())
        File "/home/tim/mambaforge/envs/aligner/lib/python3.10/site-packages/PySide6/scripts/pyside_tool.py", line 181, in designer
          qt_tool_wrapper(ui_tool_binary("designer"), sys.argv[1:])
        File "/home/tim/mambaforge/envs/aligner/lib/python3.10/site-packages/PySide6/scripts/pyside_tool.py", line 52, in qt_tool_wrapper
          pyside_dir = Path(ref_mod.__file__).resolve().parent
        File "/home/tim/mambaforge/envs/aligner/lib/python3.10/pathlib.py", line 960, in __new__
          self = cls._from_parts(args)
        File "/home/tim/mambaforge/envs/aligner/lib/python3.10/pathlib.py", line 594, in _from_parts
          drv, root, parts = self._parse_args(args)
        File "/home/tim/mambaforge/envs/aligner/lib/python3.10/pathlib.py", line 578, in _parse_args
          a = os.fspath(a)
      TypeError: expected str, bytes or os.PathLike object, not NoneType
      
      JonBJ 1 Reply Last reply
      0
      • T Tim Tu

        @friedemannkleint Thanks! I have written the register.py, but now designer can't start. (Also, I have tried the example, it doesn't work too.)

        ❯ export PYSIDE_DESIGNER_PLUGINS="registertictactoe.py"
        ❯ pyside6-designer
        Traceback (most recent call last):
          File "/home/tim/mambaforge/envs/aligner/bin/pyside6-designer", line 8, in <module>
            sys.exit(designer())
          File "/home/tim/mambaforge/envs/aligner/lib/python3.10/site-packages/PySide6/scripts/pyside_tool.py", line 181, in designer
            qt_tool_wrapper(ui_tool_binary("designer"), sys.argv[1:])
          File "/home/tim/mambaforge/envs/aligner/lib/python3.10/site-packages/PySide6/scripts/pyside_tool.py", line 52, in qt_tool_wrapper
            pyside_dir = Path(ref_mod.__file__).resolve().parent
          File "/home/tim/mambaforge/envs/aligner/lib/python3.10/pathlib.py", line 960, in __new__
            self = cls._from_parts(args)
          File "/home/tim/mambaforge/envs/aligner/lib/python3.10/pathlib.py", line 594, in _from_parts
            drv, root, parts = self._parse_args(args)
          File "/home/tim/mambaforge/envs/aligner/lib/python3.10/pathlib.py", line 578, in _parse_args
            a = os.fspath(a)
        TypeError: expected str, bytes or os.PathLike object, not NoneType
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #4

        @Tim-Tu said in How to add plugins to PySide6-designer?:

        export PYSIDE_DESIGNER_PLUGINS="registertictactoe.py"

        Per the docs https://doc-snapshots.qt.io/qtforpython-dev/tutorials/basictutorial/uifiles.html#custom-widgets-in-qt-designer

        Registering this with Qt Designer is done by providing a registration script named register*.py and pointing the path-type environment variable PYSIDE_DESIGNER_PLUGINS to the directory.

        "to the directory". So try export PYSIDE_DESIGNER_PLUGINS="." or the full path.

        T 1 Reply Last reply
        0
        • JonBJ JonB

          @Tim-Tu said in How to add plugins to PySide6-designer?:

          export PYSIDE_DESIGNER_PLUGINS="registertictactoe.py"

          Per the docs https://doc-snapshots.qt.io/qtforpython-dev/tutorials/basictutorial/uifiles.html#custom-widgets-in-qt-designer

          Registering this with Qt Designer is done by providing a registration script named register*.py and pointing the path-type environment variable PYSIDE_DESIGNER_PLUGINS to the directory.

          "to the directory". So try export PYSIDE_DESIGNER_PLUGINS="." or the full path.

          T Offline
          T Offline
          Tim Tu
          wrote on last edited by
          #5

          @JonB Thanks, that is my wrong.

          But that maybe pyside's bug. I have checked the code, and I found it tried to get the path of pyside6 by pyside_dir = Path(ref_mod.__file__).resolve().parent . But actually it just returns None.

          >>> import PySide6
          >>> print(PySide6.__file__)
          None
          

          I can solve this problem by creating __init__.py at /site-packages/PySide6/. Should I report this problem?

          JonBJ 1 Reply Last reply
          0
          • T Tim Tu

            @JonB Thanks, that is my wrong.

            But that maybe pyside's bug. I have checked the code, and I found it tried to get the path of pyside6 by pyside_dir = Path(ref_mod.__file__).resolve().parent . But actually it just returns None.

            >>> import PySide6
            >>> print(PySide6.__file__)
            None
            

            I can solve this problem by creating __init__.py at /site-packages/PySide6/. Should I report this problem?

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

            @Tim-Tu
            I only have PySide2:

            >>> import PySide2
            >>> print(PySide2.__file__)
            /home/jon/.local/lib/python3.10/site-packages/PySide2/__init__.py
            

            I don't know why your PySide6 does not have this, or what you are supposed to do about it.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Tim Tu
              wrote on last edited by
              #7

              Unluckily, it still can't work.

               ❯ ll
              total 28K
              -rw-rw-r-- 1 tim tim  435 Feb 16 09:24 main.py
              -rw-rw-r-- 1 tim tim  446 Feb 16 09:24 registertictactoe.py
              -rw-rw-r-- 1 tim tim  119 Feb 16 09:24 taskmenuextension.pyproject
              -rw-rw-r-- 1 tim tim 4.9K Feb 16 09:24 tictactoe.py
              -rw-rw-r-- 1 tim tim 1.7K Feb 16 09:24 tictactoeplugin.py
              -rw-rw-r-- 1 tim tim 2.3K Feb 16 09:24 tictactoetaskmenu.py
              ❯ export PYSIDE_DESIGNER_PLUGINS="."
              ❯ pyside6-designer
              ERROR: ld.so: object 'libpython3.10.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
              

              cd139b9a-d2aa-43f9-992c-f7edfba38b3d-image.png

              JonBJ 1 Reply Last reply
              0
              • T Tim Tu

                Unluckily, it still can't work.

                 ❯ ll
                total 28K
                -rw-rw-r-- 1 tim tim  435 Feb 16 09:24 main.py
                -rw-rw-r-- 1 tim tim  446 Feb 16 09:24 registertictactoe.py
                -rw-rw-r-- 1 tim tim  119 Feb 16 09:24 taskmenuextension.pyproject
                -rw-rw-r-- 1 tim tim 4.9K Feb 16 09:24 tictactoe.py
                -rw-rw-r-- 1 tim tim 1.7K Feb 16 09:24 tictactoeplugin.py
                -rw-rw-r-- 1 tim tim 2.3K Feb 16 09:24 tictactoetaskmenu.py
                ❯ export PYSIDE_DESIGNER_PLUGINS="."
                ❯ pyside6-designer
                ERROR: ld.so: object 'libpython3.10.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
                

                cd139b9a-d2aa-43f9-992c-f7edfba38b3d-image.png

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

                @Tim-Tu
                Dunno. Verify locate libpython3.10.so returns some matches (mine returns a dozen). Whether the error message means it cannot find it or it can but cannot load it (check output from ldd) I do not know. Nor whether ignored means it doesn't matter. I'm afraid I don't use this stuff.

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  Tim Tu
                  wrote on last edited by Tim Tu
                  #9

                  It finally work on python 3.11.
                  1baa4d26-24dd-4aed-abda-9d065590648b-image.png

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    Tim Tu
                    wrote on last edited by
                    #10

                    It still doesn't work on my code, here is my register_widgets.py:

                    from PySide6.QtDesigner import QPyDesignerCustomWidgetCollection
                    import os, sys
                    from pathlib import Path
                    import qfluentwidgets
                    
                    plugins_dir = os.path.dirname(qfluentwidgets.__file__) + '/plugins'
                    sys.path.append(plugins_dir)
                    print(plugins_dir)
                    # plugins = []
                    
                    def get_modules(py):
                        # I don't know why, but they are nessary
                        from PySide6.QtDesigner import QDesignerCustomWidgetInterface
                        from inspect import getmembers
                    
                        modules = []
                        for name, obj in getmembers(py):
                        # for name, obj in py.__dict__.items():
                            print(f"Loading {name}")
                            if isinstance(obj, QDesignerCustomWidgetInterface):
                                modules.append(obj)
                        return modules
                    
                    for filename in os.listdir(plugins_dir):
                        if filename.endswith('.py') and not filename.startswith('_'):
                            # plugins += get_modules(__import__(file_path))
                            py = __import__(f"qfluentwidgets.plugins.{filename}".replace('.py', ''))
                            for plug in get_modules(py):
                                QPyDesignerCustomWidgetCollection.addCustomWidget(plug)
                    

                    23e2e6d4-9b65-4be7-941a-0133c3bd73c3-image.png

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      Tim Tu
                      wrote on last edited by
                      #11

                      I finally made it work!
                      28952710-154a-4732-9140-4a7dd3f5f1e5-image.png
                      Thank everyone for your help.

                      H 1 Reply Last reply
                      0
                      • T Tim Tu has marked this topic as solved on
                      • T Tim Tu

                        I finally made it work!
                        28952710-154a-4732-9140-4a7dd3f5f1e5-image.png
                        Thank everyone for your help.

                        H Offline
                        H Offline
                        Hassaan11
                        wrote on last edited by
                        #12

                        @Tim-Tu
                        Hey!
                        Sorry for replying to a closed topic, but would be so kind as to provide me with the code you used to register the plugin? I am also trying to get qfluentwidgets to work on my designer but having some problems, this would save a lot of trouble!
                        Thanks

                        T 1 Reply Last reply
                        0
                        • H Hassaan11

                          @Tim-Tu
                          Hey!
                          Sorry for replying to a closed topic, but would be so kind as to provide me with the code you used to register the plugin? I am also trying to get qfluentwidgets to work on my designer but having some problems, this would save a lot of trouble!
                          Thanks

                          T Offline
                          T Offline
                          Tim Tu
                          wrote on last edited by
                          #13

                          @Hassaan11 Hi, I'm sorry for my late reply. Should you still require the information, kindly visit my repository.

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            AndreBam
                            wrote on last edited by
                            #14

                            @JonB Just following the tutorial here https://doc.qt.io/qtforpython-6/examples/example_designer_taskmenuextension.html#task-menu-extension-example. I'm wondering if it's possible to have the required files in different directories.

                            JonBJ 1 Reply Last reply
                            0
                            • A AndreBam

                              @JonB Just following the tutorial here https://doc.qt.io/qtforpython-6/examples/example_designer_taskmenuextension.html#task-menu-extension-example. I'm wondering if it's possible to have the required files in different directories.

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

                              @AndreBam I don't use designer plugins, let alone PySide/PySide6, so I'm not the person to ask.

                              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