[PyQt] returning a value from a sub-dialog

Johoski, Timothy R timothy.r.johoski at intel.com
Thu Jul 25 22:02:09 BST 2013


I'm a newbie, so take this with a grain of salt...  The quick example below shows a dialog with a label and line edit, then after the user presses OK or Cancel (or hits return or escape), it prints what they typed in the line edit.  Hope this helps.
- Tim

#/usr/bin/env python
import sys

from PyQt4.QtCore import *
from PyQt4.QtGui import *

app = QApplication(sys.argv)
dlg = QDialog()

l  = QLabel("Enter name:")
le = QLineEdit()
hl = QHBoxLayout()
hl.addWidget(l)
hl.addWidget(le)

bb = QDialogButtonBox(dlg)
bb.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok)
bb.accepted.connect(dlg.accept)
bb.rejected.connect(dlg.reject)

vl = QVBoxLayout(dlg)
vl.addLayout(hl)
vl.addWidget(bb)

retval = dlg.exec_()
name = le.text()

print "Dialog retval=%s, name entered=\"%s\"" % (retval, name)


> From: pyqt-bounces at riverbankcomputing.com [mailto:pyqt-bounces at riverbankcomputing.com] On Behalf Of Hajas, Wayne
> Sent: Thursday, July 25, 2013 11:36 AM
> To: pyqt at riverbankcomputing.com
> Subject: [PyQt] returning a value from a sub-dialog
> 
> I am hoping somebody can point me to a simple example to do the following:
> After a Dialog is created and filled-in by the user, get the values returned to the rest of the application.
> 
> I have built applications around a single dialog.  Everything gets done under the single dialog-class.  I can get it to work.
> 
> In the current application I am building, I need multiple dialogs.   I can generate the extra dialogs but I can't figure out how to retrieve the data so I can use it elsewhere in the application.
> 
> I think the solution is going to be trivial once I see it.  But I can't figure it out right now and I can't come up with the right google-search.
> 
> Thanks in advance,
> Wayne Hajas


More information about the PyQt mailing list