How to create custom widget plugin for Qt Designer with Qt for Python?
-
Hi,
I'm using Qt for python as it was a low hanging fruit to make my small application working on Windows, Linux and MacOS (this is why I'm not interested in a C-based solution).I created several custom UI-widgets. And then I used "Promote to..." feature of Qt Designer to incorporate them in my forms. It works but I see that it brings me extra code that does only correct placement and alignment of layouts. It would be definitely better to get rid of this code and give this job to Qt Designer and auto-generated code. I.e. incorporate my custom widget into Qt Designer instead of usage of widget promotion.
So, I started to search a way to create custom widget plugin for Qt Designer and found only 2 sources of information:
- The page in Qt documentation - but I see it describes the process for C++ and use some compiler/linker flags. So I don't understand how to apply the same in python
- An old article in Qt Quaterly - it describes the process for PyQt4 and looks quite stright-forward. But... it seems to be outdated. At least I can't find class QPyDesignerCustomWidgetPlugin for example to derive my custom plugin from it.
So, my question is - is it possible to create custom widget plugin for Qt Designer with pure PySide2/PySide6?
-
For anyone searching for the same thing. It is now possible with Qt for Python to create a QtDesigner plugin in Python:
https://doc.qt.io/qtforpython/tutorials/basictutorial/uifiles.html#custom-widgets-in-qt-designer -
@StarterKit
think you should read https://stackoverflow.com/questions/52128188/using-a-custom-pyside2-widget-in-qt-designer. Though it has a strangely unterminated answer from @eyllanesc , who visits this forum and may see this post....My impression is that you need to stick with Promotion. Designer custom widget may be possible from PyQt, but not from PySide.
application working on Windows, Linux and MacOS (this is why I'm not interested in a C-based solution).
You may have your own good reasons for wanting to use Python, but I don't know what you are implying here. A C++ solution would indeed work, and allow custom widget design for use in Designer, across all these platforms.
-
@JonB said in How to create custom widget plugin for Qt Designer with Qt for Python?:
You may have your own good reasons for wanting to use Python, but I don't know what you are implying here. A C++ solution would indeed work, and allow custom widget design for use in Designer, across all these platforms.
Ok, I see that I put it in unclear way. I meant to say I already have several different widgets created with python and don't wish to re-write them in C++. I agree with you that I may re-create it with C++ and it will work but I really don't wish to do it.
Thanks for the link to stackoverflow, I'll take a look there. Promotion works good but it's not so comfortable to fine-tune placement of different parts in UI - this is why I'm looking for other possible options.
-
For anyone searching for the same thing. It is now possible with Qt for Python to create a QtDesigner plugin in Python:
https://doc.qt.io/qtforpython/tutorials/basictutorial/uifiles.html#custom-widgets-in-qt-designer -