Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Super Call with QT Promoted Widget



  • OS: Windows
    QT Version: 5.11.1
    Python Version: 3.7.8

    I created a class that inherits QGraphicsView and replaced it with promoting action on qt designer. At inherited call (no event replaced / no modification) its built-in methods running well as you will see below (First Code and Output). On the other hand, I can replace mouseMoveEvent with my own method and it is also working well by itself.

    But the problem is when I want to do super call to use built-in code before my method, super does not work and still gets the same output as the normal replaced one (As you see at Second Code and Output).

    Inherited Class Code (Promoted in QT Designer);

    class Graphics_View(QGraphicsView):
            mouse_Events = dict()
    
            def __init__(self, *args, parent=None, obj=None, **kwargs):
                    super(Graphics_View, self).__init__(*args, **kwargs)
                    self.mouse_Events["mouseMove_position"] = None
            
            
            def mouseMoveEvent(self, event):
                    print("self.mouse_Events[mouseMove_position]", event.pos())
            
                    # CURRENT POSITION
                    self.mouse_Events["mouseMove_position"] = event.pos()
                    self.mouse_Events["mouseMove_position_scene"] = self.mapToScene(
                            self.mouse_Events["mouseMove_position"]
                    )
    

    Terminal Outputs;

    self.mouse_Events[mouseMove_position] PyQt5.QtCore.QPoint(674, 223)
    self.mouse_Events[mouseMove_position] PyQt5.QtCore.QPoint(692, 229)
    self.mouse_Events[mouseMove_position] PyQt5.QtCore.QPoint(712, 236)
    self.mouse_Events[mouseMove_position] PyQt5.QtCore.QPoint(729, 242)
    

    Main Window Code;

    class Ui_Modified(Structure_Ui_Camera):
            def __init__(self, *args, obj=None, **kwargs):
                    # Call super for built-in initialize
                    super(Ui_Modified, self).__init__(*args, **kwargs)
            
                    self.graphicsView_Main.mouseMoveEvent = self.Graphics_View_MouseMove_Event_Handler_LCDNumber
    
            def Graphics_View_MouseMove_Event_Handler_LCDNumber(self, event):
                    super(Graphics_View).mouseMoveEvent(event)  # Not working
            
                    background_item = self.graphicsView_Main.mouse_Events["mouseMove_current_item"]
                    print("bi", background_item)
    

    Terminal Outputs;

    bi None
    bi None
    bi None
    bi None
    bi None
    

    When I change super call as below, app crashes;

    Inherited Class Code - Different Super Call;

            def Graphics_View_MouseMove_Event_Handler_LCDNumber(self, event):
                    # super(type(self.graphicsView_Main), self.graphicsView_Main).mouseMoveEvent(event)
                    super(Graphics_View, self).mouseMoveEvent(event)
    

    Terminal Outputs;

    super(Graphics_View, self).mouseMoveEvent(event)
    TypeError: super(type, obj): obj must be an instance or subtype of type
    


  • @msaidbilgehan
    I don't understand. You are using

    super(Graphics_View).mouseMoveEvent(event)  # Not working
    

    inside a method in class Ui_Modified, so how do you expect to be able to use super(Graphics_View) anything, since it's not derived from Graphics_View?



  • @JonB I am a bit confused. Because after connection of mouseMoveEvent isn't super call will be called at graphicsView_Main with parent parameter as Graphics_View which is also the base class of graphicsView_Main?

    It is not a good idea to write mouse events in the UI sub-class but we need to connect graphicsView and UI variables and status to track mouse features and decide to do actions in UI at that time (It is legacy code).

    Actually, we updated the code and now we don't have the issue, every class has its own subclass and methods, not dependent. But I am missing something on this issue, and maybe its answer will refresh my mind.



  • @msaidbilgehan
    Sorry, don't know what you are saying. In your original I see:

    class Ui_Modified(Structure_Ui_Camera):
            def __init__(self, *args, obj=None, **kwargs):
                    # Call super for built-in initialize
                    super(Ui_Modified, self).__init__(*args, **kwargs)
    
            def Graphics_View_MouseMove_Event_Handler_LCDNumber(self, event):
                    super(Graphics_View).mouseMoveEvent(event)  # Not working
    

    The super(Ui_Modified, self) in __init__() looks right, since you are in class Ui_Modified. But the super(Graphics_View) in Graphics_View_MouseMove_Event_Handler_LCDNumber() does not look right, since you are not in class Graphics_View. You certainly could not do this in C++. And since you say it is not working it would seem it;s problematic. That's all I know.



  • @JonB I see. What kind of way we should use to connect mouse x and y positions to LCD Number such as below image;

    e6db5c82-bf4d-40c8-878d-8966e8fd7655-image.png

    I am planning to create abstract classes and a guide will be good for the start. Any help will be appreciated!


Log in to reply