WinPython环境下向Qt Designer导入Shotgun自定义PyQt5组件遇阻
Hey there, let's walk through getting those Shotgun custom widgets loaded into Qt Designer in your WinPython setup—this is totally doable once you nail down the plugin registration steps.
First, Confirm Your WinPython Qt Paths
WinPython is a self-contained environment, so its Qt tools and plugin directories are separate from your system's Qt. Here's what to track down:
- Qt Designer executable: Look in your WinPython install folder, usually something like
WinPython-64bit-3.x.y\Qt\bin\designer.exe - Designer plugin directory: This is where we'll drop our custom widget plugin. Two common locations to check:
WinPython-64bit-3.x.y\Qt\plugins\designer- If you're using PySide2/PyQt5 via pip in WinPython, check
WinPython-64bit-3.x.y\python-3.x.y\Lib\site-packages\PySide2\plugins\designer(orPyQt5instead ofPySide2)
Step 1: Install tk-framework-qtwidgets in WinPython
First, make sure the framework is installed in your WinPython environment. Open the WinPython Command Prompt and:
- If the package is available on PyPI, run:
pip install tk-framework-qtwidgets - If not, clone the official repository locally, navigate to the repo directory in the WinPython Command Prompt, and run:
pip install .
(If you already have it installed, skip this—just double-check it's in WinPython's site-packages, not another Python environment.)
Step 2: Write a Custom Widget Plugin Script
Qt Designer needs a plugin wrapper to recognize Python-based widgets. Create a file named shotgun_widgets_plugin.py and paste the code below (adjust for the specific widgets you want to load):
# Adjust import to PyQt5 if you're using that instead of PySide2 from PySide2 import QtGui, QtWidgets, QtDesigner # Import the specific widgets from tk-framework-qtwidgets from tk_framework_qtwidgets.widgets import ShotgunListWidget, ShotgunTreeWidget class ShotgunWidgetPluginBase(QtDesigner.QPyDesignerCustomWidgetPlugin): def __init__(self, parent=None): super().__init__(parent) self.initialized = False def initialize(self, core): if self.initialized: return self.initialized = True def isInitialized(self): return self.initialized def isContainer(self): return False # Register ShotgunListWidget class ShotgunListWidgetPlugin(ShotgunWidgetPluginBase): def createWidget(self, parent): return ShotgunListWidget(parent) def name(self): return "ShotgunListWidget" def group(self): return "Shotgun Widgets" def icon(self): # Optional: Point to an icon file from the tk-framework if you want return QtGui.QIcon() def toolTip(self): return "Custom list widget for Shotgun integrations" def whatsThis(self): return "A Qt list widget optimized for Shotgun data workflows" def includeFile(self): return "tk_framework_qtwidgets.widgets.ShotgunListWidget" # Register ShotgunTreeWidget (repeat this pattern for other widgets) class ShotgunTreeWidgetPlugin(ShotgunWidgetPluginBase): def createWidget(self, parent): return ShotgunTreeWidget(parent) def name(self): return "ShotgunTreeWidget" def group(self): return "Shotgun Widgets" def icon(self): return QtGui.QIcon() def toolTip(self): return "Custom tree widget for Shotgun integrations" def whatsThis(self): return "A Qt tree widget optimized for Shotgun data workflows" def includeFile(self): return "tk_framework_qtwidgets.widgets.ShotgunTreeWidget"
Step 3: Install the Plugin
Copy the shotgun_widgets_plugin.py file into the Designer plugin directory you found earlier.
Step 4: Launch Qt Designer Correctly
To make sure Designer picks up WinPython's Python environment and the plugin:
- Open the WinPython Command Prompt (not your system's cmd)
- Navigate to the Qt bin directory (e.g.,
cd WinPython-64bit-3.x.y\Qt\bin) - Run
designer.exefrom the command line—this ensures it uses WinPython's PYTHONPATH and can find the tk-framework modules.
Step 5: Verify the Widgets Load
Open Qt Designer, go to the Widget Box on the left. You should see a new group called "Shotgun Widgets" with your registered widgets inside. If they don't show up:
- Check the command line output for error messages (common issues: missing imports, wrong Qt version mismatch)
- Double-check that the plugin file is in the correct Designer plugin directory
- Confirm that the
includeFilepaths in the plugin script match the actual import paths of the tk-framework widgets
Quick Troubleshooting Tips
- Qt Version Mismatch: Make sure WinPython's Qt version (PySide2/PyQt5) matches the version tk-framework-qtwidgets was built for. You can check with
pip show PySide2in WinPython's command prompt. - PYTHONPATH Issues: If Designer can't find the tk-framework modules, set the PYTHONPATH environment variable explicitly before launching Designer:
set PYTHONPATH=WinPython-64bit-3.x.y\python-3.x.y\Lib\site-packages designer.exe - Widget-Specific Errors: If a particular widget fails to load, try registering just that one widget first to isolate the issue.
Let me know if you run into any specific roadblocks—this setup can be finicky with paths, but once it clicks, it works smoothly!
内容的提问来源于stack exchange,提问作者Jan

