PYQT 3 communication with 2 windows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marcpp

    #1

    PYQT 3 communication with 2 windows

    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?

  • David Boddie

    #2
    Re: PYQT 3 communication with 2 windows

    On Thursday 19 April 2007 22:38, Marcpp wrote:
    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(sel f.tr("&OK"), self)
    self.connect(ok Button, SIGNAL("clicked ()"), self.sendText)
    layout = QVBoxLayout(sel f)
    layout.addWidge t(self.textEdit )
    layout.addWidge t(okButton)

    def sendText(self):

    self.emit(PYSIG NAL("textEntere d(QString)"), (self.textEdit. text(),))


    def fn(text):

    print text

    if __name__ == "__main__":

    app = QApplication(sy s.argv)
    window = Window()
    window.connect( window, PYSIGNAL("textE ntered(QString) "), fn)
    window.show()
    app.setMainWidg et(window)
    sys.exit(app.ex ec_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

    Comment

    • Marcpp

      #3
      Re: PYQT 3 communication with 2 windows

      On 21 abr, 02:43, David Boddie <d...@boddie.or g.ukwrote:
      On Thursday 19 April 2007 22:38, Marcpp wrote:
      >
      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(sel f.tr("&OK"), self)
      self.connect(ok Button, SIGNAL("clicked ()"), self.sendText)
      layout = QVBoxLayout(sel f)
      layout.addWidge t(self.textEdit )
      layout.addWidge t(okButton)
      >
      def sendText(self):
      >
      self.emit(PYSIG NAL("textEntere d(QString)"), (self.textEdit. text(),))
      >
      def fn(text):
      >
      print text
      >
      if __name__ == "__main__":
      >
      app = QApplication(sy s.argv)
      window = Window()
      window.connect( window, PYSIGNAL("textE ntered(QString) "), fn)
      window.show()
      app.setMainWidg et(window)
      sys.exit(app.ex ec_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.

      Comment

      • Marcpp

        #4
        Re: PYQT 3 communication with 2 windows

        On 21 abr, 02:43, David Boddie <d...@boddie.or g.ukwrote:
        On Thursday 19 April 2007 22:38, Marcpp wrote:
        >
        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(sel f.tr("&OK"), self)
        self.connect(ok Button, SIGNAL("clicked ()"), self.sendText)
        layout = QVBoxLayout(sel f)
        layout.addWidge t(self.textEdit )
        layout.addWidge t(okButton)
        >
        def sendText(self):
        >
        self.emit(PYSIG NAL("textEntere d(QString)"), (self.textEdit. text(),))
        >
        def fn(text):
        >
        print text
        >
        if __name__ == "__main__":
        >
        app = QApplication(sy s.argv)
        window = Window()
        window.connect( window, PYSIGNAL("textE ntered(QString) "), fn)
        window.show()
        app.setMainWidg et(window)
        sys.exit(app.ex ec_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.

        Comment

        Working...