Pyqt5 acces GUI elements from subclass
<p>Need a help to read and write to GUI elements from subclass.
The code:</p>

<pre><code>UI element:
[] doABC 

# main.py
import mySubclass

class myAppController(QtWidgets.QMainWindow):

    def __init__(self):
        super(myAppController, self).__init__()

        # load view
        uifile = 'myApp.ui'
        uic.loadUi(uifile, self)

        # I can access UI elements like that
        self.pb_Verify.clicked.connect(self.slot_verify) # for slot in main.py

        # Calling slot from mySubclass
        self.pb_EliminateVerifErrors.clicked.connect(mySubclass.fixErrors)

# Show Main window
if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    window = myAppController()
    window.show()
    sys.exit(app.exec_())

# mySubclass.py - separate file
def fixErrors(self):
    # here I want to check state of checkbox
    if doABC.isChecked():
</code></pre>

<p>The problem is that <code>self.doABC.isChecked()</code> is not working in this case.
I have also tried to pass additional parameters with slot call from <code>main.py</code> including <code>self</code> or <code>self.doABC</code> but it is not working in this way. Also trying to access <code>main.doABC</code> or <code>super().doABC</code> is not an option.</p>

<p>Done a lot of search on google but nothing fit to my case.</p>

<p>My level is beginner in GUI programming so I even do not know hot it suppose to be.</p>

<p>Your problem is that mysubclass needs a reference to doABC to check it.</p>

<p>Here is a working example:</p>

<p>main.py file</p>

<pre><code>#!python3
# main.py
import mySubclass
import sys
from PyQt5 import QtWidgets, uic


class myAppController(QtWidgets.QMainWindow):

    def __init__(self):
        super(myAppController, self).__init__()

        # load view
        uifile = 'myApp.ui'
        uic.loadUi(uifile, self)

        # I can access UI elements like that
        # self.pb_Verify.clicked.connect(self.slot_verify) # for slot in main.py

        # Calling slot from mySubclass
        self.pb_EliminateVerifErrors.clicked.connect(self.EliminateErrors)

    def EliminateErrors(self):
        mySubclass.fixErrors(self.doABC)

# Show Main window
if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    window = myAppController()
    window.show()
    sys.exit(app.exec_())
</code></pre>

<p>Here I added a class function to be called by the signal and pass a reference to doABC.  </p>

<p>mySubclass.py</p>

<pre><code># mySubclass.py - separate file
def fixErrors(doABC):
    # here I want to check state of checkbox
    if doABC.isChecked():
        print("Works!")
</code></pre>

<p>Here I removed self from the function arguments as it is not a class function.</p>

<p>That's it! You were pretty close!</p>

python subclass pyqt5