P
P
Papshoika2014-06-09 18:19:45
Python
Papshoika, 2014-06-09 18:19:45

PyQt exchange data between modules

There is a module generated via pyuic4 with the Ui_DockWidget class. It has a QTextEdit. Several functions have been added to the same class that insert text into textEdit. For example, the function

def textadd(self):
                self.textEdit.setText("TEXT1")

And there is the main window. It contains code that defines the main window and adds a QDockWidget to the right.
app = QtGui.QApplication
mw = app.activeWindow() 
editor= QtGui.QDockWidget()
editor.ui = mymodule.Ui_DockWidget()
editor.ui.setupUi(editor) 
mw.addDockWidget(QtCore.Qt.RightDockWidgetArea, editor)

Question: how to call the text1 function of the mymodule module from the main window and see the inserted text in the QDockWidget already added to the right?
In addition, I will say that there have been attempts to add a signal attribute to the Ui_DockWidget class. But calling the textadd function in it did not work. Also, these functions will need to be called from another module, which will be connected as another DockWidget.
It seems to me that I do not understand something very simple and fundamental, perhaps I do not separate the interface from everything else, but the examples in the PyQt C ++ documentation and so far have not helped me understand my main mistake. So what is she?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
yttrium, 2014-06-10
@yttrium

the foundation is here

P
Papshoika, 2014-06-10
@Papshoika

It worked as a result of the following actions:
1.Created signal class
2. Declared a global variable of type QWidget.
3. TextEdit is passed to the global variable.
4. + a function that adds text to edit, eg myglobalvar.append('text')
5. + a function that calls a signal by passing function (4) to it in the slot and then emits.
mysignal.connect(textadd)
mysignal.emit()
As a result, text can be added from another module by calling the function in which the signal is connected.
What are the problems with this solution? That is, it works, but maybe something should not be done?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question