[PyQt] accessing variables of class
Vincent Vande Vyvre
vincent.vandevyvre at swing.be
Fri May 11 15:47:12 BST 2012
On 11/05/12 15:13, Enes Albay wrote:
> Hi,
>
> when i change
>
> class A(QtGui.QMainWindow):
> ....
> def setupUI(self):
> self.lineEdit = QtGui.QLineEdit()
> self.b = B()
> self.b.c.clicked.connect(self.handleLetter)
> ...
>
> def handleLetter(self):
> self.lineEdit.setText("Hello")
>
> there is no compilation or running error. But, lineEdit text doesn't
> change, nothing happening.
>
>
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
Why don't you pass a reference of the main windows to your's subclass?
This example is working:
-------------------------------
class A(object):
def setupUI(self, MainWindow):
self.layout = QtGui.QVBoxLayout()
self.lineEdit = QtGui.QLineEdit(MainWindow)
self.b = B(self, MainWindow)
self.b.setGeometry(0, 30, 80, 35)
MainWindow.show()
class B(QtGui.QWidget):
def __init__(self, main, parent=None):
super(B, self).__init__(parent)
self.c = C(main, self)
class C(QtGui.QPushButton):
def __init__(self, main, parent=None):
super(C, self).__init__(parent)
self.main = main
self.clicked.connect(self.handleLetter)
def handleLetter(self):
self.main.lineEdit.setText('Hello')
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
mw = QtGui.QMainWindow()
a = A()
a.setupUI(mw)
sys.exit(app.exec_())
-----------------------------------------------
Cheers
--
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte+7
<https://launchpad.net/qarte+7> . PaQager <https://launchpad.net/paqager>
More information about the PyQt
mailing list