Skip to content Skip to sidebar Skip to footer

Catching Events Within Qtdesigner Generated Widget

I'm trying to make an app that would allow to manipulate some objects within QGraphicsView/QGraphicScene using the mouse (adding, moving, resizing, etc.). The UI is generated from

Solution 1:

The reason the events aren't caught is because in the .py file generated from the QtDesigner file, self.DesignWindowView is still a QtWidgets.QGraphicsView object. The solution to this is to promote the QtWidgets.QGraphicsView in Qt Designer to a DesignerWindowView object.

For this it's best to put the definition of DesignerWindowView in a separate .py file (e.g. designerwindowview.py) to prevent circular dependencies between the main .py file and the .py file generated from the QtDesigner file.

In designer, right-click on the widget that you want to promote and choose Promote to .... Fill in the promoted class name (DesignerWindowView). For the name of the header file you should fill in the name of the .py file with the definition of the promoted class without the .py extension (e.g. designerwindowview).

Save and run through pyuic5 as before. In the generated .py file self.DesignWindowView should now be a DesignWindowView object, and there should be an import statement similar to from designwindowview import DesignWindowView at the bottom of the .py file.

Post a Comment for "Catching Events Within Qtdesigner Generated Widget"