PYQT 3 communication with 2 windows

M

Marcpp

Hi, I'm introducing to program in python + pyqt.
I have a main window that call a second window (to introduce a info
with textedit)
when press the second window button I need to return to the main
window the info
introduced in the second window.
I've seek in the pyqt doc examples but i don't find it.
Have you any example?
 
D

David Boddie

Hi, I'm introducing to program in python + pyqt.
I have a main window that call a second window (to introduce a info
with textedit)
when press the second window button I need to return to the main
window the info
introduced in the second window.
I've seek in the pyqt doc examples but i don't find it.
Have you any example?

You could connect the button to a slot in the second window that sends
the text back to the first window.

Here's an example that sends the text to a function. You could substitute a
class for the function to get what you want.


import sys
from qt import *

class Window(QWidget):

def __init__(self, parent = None):

QWidget.__init__(self, parent)

self.textEdit = QTextEdit(self)
okButton = QPushButton(self.tr("&OK"), self)
self.connect(okButton, SIGNAL("clicked()"), self.sendText)
layout = QVBoxLayout(self)
layout.addWidget(self.textEdit)
layout.addWidget(okButton)

def sendText(self):

self.emit(PYSIGNAL("textEntered(QString)"), (self.textEdit.text(),))


def fn(text):

print text

if __name__ == "__main__":

app = QApplication(sys.argv)
window = Window()
window.connect(window, PYSIGNAL("textEntered(QString)"), fn)
window.show()
app.setMainWidget(window)
sys.exit(app.exec_loop())


Note the use of PYSIGNAL() instead of SIGNAL(). With PyQt4 you would be able
to use SIGNAL() and write the emit() call in a simpler form.

David
 
M

Marcpp

You could connect the button to a slot in the second window that sends
the text back to the first window.

Here's an example that sends the text to a function. You could substitute a
class for the function to get what you want.

import sys
from qt import *

class Window(QWidget):

def __init__(self, parent = None):

QWidget.__init__(self, parent)

self.textEdit = QTextEdit(self)
okButton = QPushButton(self.tr("&OK"), self)
self.connect(okButton, SIGNAL("clicked()"), self.sendText)
layout = QVBoxLayout(self)
layout.addWidget(self.textEdit)
layout.addWidget(okButton)

def sendText(self):

self.emit(PYSIGNAL("textEntered(QString)"), (self.textEdit.text(),))

def fn(text):

print text

if __name__ == "__main__":

app = QApplication(sys.argv)
window = Window()
window.connect(window, PYSIGNAL("textEntered(QString)"), fn)
window.show()
app.setMainWidget(window)
sys.exit(app.exec_loop())

Note the use of PYSIGNAL() instead of SIGNAL(). With PyQt4 you would be able
to use SIGNAL() and write the emit() call in a simpler form.

David


Thankyou!!!
This is that I want.
 
M

Marcpp

You could connect the button to a slot in the second window that sends
the text back to the first window.

Here's an example that sends the text to a function. You could substitute a
class for the function to get what you want.

import sys
from qt import *

class Window(QWidget):

def __init__(self, parent = None):

QWidget.__init__(self, parent)

self.textEdit = QTextEdit(self)
okButton = QPushButton(self.tr("&OK"), self)
self.connect(okButton, SIGNAL("clicked()"), self.sendText)
layout = QVBoxLayout(self)
layout.addWidget(self.textEdit)
layout.addWidget(okButton)

def sendText(self):

self.emit(PYSIGNAL("textEntered(QString)"), (self.textEdit.text(),))

def fn(text):

print text

if __name__ == "__main__":

app = QApplication(sys.argv)
window = Window()
window.connect(window, PYSIGNAL("textEntered(QString)"), fn)
window.show()
app.setMainWidget(window)
sys.exit(app.exec_loop())

Note the use of PYSIGNAL() instead of SIGNAL(). With PyQt4 you would be able
to use SIGNAL() and write the emit() call in a simpler form.

David


Thankyou!!!
This is that I want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top