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?

How to add plugins to PySide6-designer?

Scheduled Pinned Locked Moved Solved Qt for Python
15 Posts 5 Posters 2.6k Views
  • 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.
  • T Offline
    T Offline
    Tim Tu
    wrote on 2 Mar 2024, 05:42 last edited by
    #1

    Hi all,
    I'm trying to add some Custom Widgets into PySide6-designer, but I don't know how to make designer load them. Here is a python script that's work well on PyQt5. I want to make it work on PySide6, so I simply replaced PyQt5 to PySide6, but it doesn't work.

    When I check Plugin Information, I found this:
    d005334e-9f9f-4b04-a709-a426a685f254-image.png

    Please help me, thanks.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Tim Tu
      wrote on 8 Mar 2024, 15:25 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 3 Jun 2024, 20:21
      0
      • F Offline
        F Offline
        friedemannkleint
        wrote on 2 Mar 2024, 20:52 last edited by friedemannkleint 3 Feb 2024, 20:55
        #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 3 Mar 2024, 10:27
        0
        • F friedemannkleint
          2 Mar 2024, 20:52

          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 3 Mar 2024, 10:27 last edited by Tim Tu 3 Mar 2024, 10:30
          #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
          
          J 1 Reply Last reply 3 Mar 2024, 10:39
          0
          • T Tim Tu
            3 Mar 2024, 10:27

            @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
            
            J Online
            J Online
            JonB
            wrote on 3 Mar 2024, 10:39 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 3 Mar 2024, 10:58
            0
            • J JonB
              3 Mar 2024, 10:39

              @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 3 Mar 2024, 10:58 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?

              J 1 Reply Last reply 3 Mar 2024, 11:04
              0
              • T Tim Tu
                3 Mar 2024, 10:58

                @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?

                J Online
                J Online
                JonB
                wrote on 3 Mar 2024, 11:04 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 3 Mar 2024, 11:08 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

                  J 1 Reply Last reply 3 Mar 2024, 11:30
                  0
                  • T Tim Tu
                    3 Mar 2024, 11:08

                    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

                    J Online
                    J Online
                    JonB
                    wrote on 3 Mar 2024, 11:30 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 3 Mar 2024, 13:38 last edited by Tim Tu 3 Mar 2024, 13:38
                      #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 3 Mar 2024, 14:31 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 8 Mar 2024, 15:25 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 3 Jun 2024, 20:21
                          0
                          • T Tim Tu has marked this topic as solved on 8 Mar 2024, 15:25
                          • T Tim Tu
                            8 Mar 2024, 15:25

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

                            H Offline
                            H Offline
                            Hassaan11
                            wrote on 3 Jun 2024, 20:21 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 22 Jun 2024, 11:20
                            0
                            • H Hassaan11
                              3 Jun 2024, 20:21

                              @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 22 Jun 2024, 11:20 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 24 Jul 2024, 11:52 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.

                                J 1 Reply Last reply 24 Jul 2024, 11:56
                                0
                                • A AndreBam
                                  24 Jul 2024, 11:52

                                  @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.

                                  J Online
                                  J Online
                                  JonB
                                  wrote on 24 Jul 2024, 11:56 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