How to add plugins to PySide6-designer?
-
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 replacedPyQt5
toPySide6
, but it doesn't work.When I check
Plugin Information
, I found this:
Please help me, thanks.
-
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.
-
@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
-
@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 variablePYSIDE_DESIGNER_PLUGINS
to the directory."to the directory". So try
export PYSIDE_DESIGNER_PLUGINS="."
or the full path. -
@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 returnsNone
.>>> import PySide6 >>> print(PySide6.__file__) None
I can solve this problem by creating
__init__.py
at/site-packages/PySide6/
. Should I report this problem? -
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.
-
@Tim-Tu
Dunno. Verifylocate 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 fromldd
) I do not know. Nor whetherignored
means it doesn't matter. I'm afraid I don't use this stuff. -
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)
-
-
@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 -
@Hassaan11 Hi, I'm sorry for my late reply. Should you still require the information, kindly visit my repository.