[PyQt] acces to object in different class

Kyle Altendorf sda at fstab.net
Thu Nov 17 17:28:46 GMT 2016


On 2016-11-17 11:58, lucaberto at libero.it wrote:

> Hello i'm using eric as ide and i have two class
> 
> class Form(QWidget, Ui_Form):
> """
> Class documentation goes here.
> """
> def __init__(self, parent=None):
> """
> Constructor
> 
> @param parent reference to the parent widget
> @type QWidget
> """
> super(Form,  self).__init__(parent)
> self.setupUi(self)
> self.tabWidget.setCurrentIndex(0)
> combo = QComboBox()
> self.disegno = Cornice(Form)
> 
> def on_pushButton_7_clicked(self):
> """
> Slot documentation goes here.
> """
> # TODO: not implemented yet
> #raise NotImplementedError
> self.lista_dati_prova = [........]
> lista_dati = self.dati_prova
> self.lineEdit.setText('test')
> self.disegno.cornice(lista_dati)
> 
> class Cornice():
> 
> def __init__(self, parent=None):
> """
> Constructor
> 
> @param parent reference to the parent widget
> @type QWidget
> """
> lista_dati = []
> 
> def cornice(self, lista_dati):
> import math
> freqfinale = lista_dati[0]
> spostamento = lista_dati[2]
> nome_cal = self.lineEdit.text()
> 
> How i can access to self.lineEdit without passing parameter from the 
> class Form and without using signal, but asking directly from Cornice 
> class?

I'm not sure why you have those restrictions, but you probably mean to 
do:

   self.disegno = Cornice(self)

To set the Cornice's parent to that instance of the Form rather than the 
Form class.  But, Cornice doesn't inherit from QObject or otherwise save 
the parent parameter.  If it did either of those then you could do one 
of the following (depending on which option you choose):

   self.parent.lineEdit.text()
   self.parent().lineEdit.text()

Cheers,
-kyle


More information about the PyQt mailing list