[PyQt] Accessing PyQt designer

David Boddie david at boddie.org.uk
Mon Oct 19 22:24:11 BST 2015


On Tue Oct 13 15:41:28 BST 2015, Carl Wolff wrote:

> can somebody help me with adding functionality to designer with python,
> preferably by some code examples?

What functionality do you want to add?

> I already succeeded to create custom python widgets and to expose them to
> designer: so that is not a problem.
> 
> But the documentation states also the following code in
> http://doc.qt.io/qt-4.8/qdesignerformwindowmanagerinterface.html , but for
> me it is totally unclear how to proceed from here with Python.

As far as I can remember, a lot of the classes like that expose details of
Designer's implementation without really providing a convenient way to extend
Designer itself, other than by using a custom widget plugin (or another type
of plugin) as a way of running the code you want to extend Designer with.

It looks like Designer passes a QDesignerFormEditorInterface instance to your
plugins's initialize method:

  http://doc.qt.io/qt-4.8/qdesignercustomwidgetinterface.html#initialize

You can then call its formWindowManager method to get a
QDesignerFormWindowManagerInterface instance:

  http://doc.qt.io/qt-4.8/qdesignerformeditorinterface.html#formWindowManager

Then you can access the form windows using the window manager interface:

  http://doc.qt.io/qt-4.8/qdesignerformwindowmanagerinterface.html

So, to summarize, in your QPyDesignerCustomWidgetPlugin class, you do
something like this with the initialize method:

def initialize(formEditor):

    windowManager = formEditor.formWindowManager()
    for i in range(windowManager.formWindowCount()):
        window = windowManager.formWindow(i)

Hope this helps,

David


More information about the PyQt mailing list