Sherafati
Sherafati

Reputation: 216

Using methods of a parent class in PyQt5

Let's say we have imported: from PyQt5.QtWidgets import QApplication, QWidget, QPushButton.

and we have created a class which inherits from QWidgets:

class mainwindow(QWidget):
    def __init__(self):
        super().__init__()

        self.createUI()
    def createUI():

If we write this : act1 = QAction("close",self) inside our class, can we say that we are using a method(QAction in this case) which is present in the parent class(QWidget)?? If yes, why don't we call the parent class name before the method name like this: act1 = QWidget.QAction("close",self)?

As far as i know when we want to use a method or attribute of a parent class inside our child class we will have to call the parent class name before the name of the method or attribute.

Upvotes: 0

Views: 108

Answers (2)

baysal celik
baysal celik

Reputation: 22

You don't use parent class for these cases.

Upvotes: 0

Rennnyyy
Rennnyyy

Reputation: 86

First of all, QAction is not a method of the class QWidget, as @bnaecker pointed out already.

Furthermore, you don't need to call methods of you parent class explicitly if they are not overriden by the child class. The interpreter automaticly does that for you.

Upvotes: 1

Related Questions