I've created a simple custom QDialog with three QLineEdits. When clicking the "OK" button I want to read the entered text and return them to the MainWindow object where the values will be stored in a list.
How do I return the values from the QDialog class so I can store them in the list in the MainWindow class, and how do I call it properly?
This is the code I have at the moment:
deviceList = []
def openAddDialog(self):
print "running openAddDialog..."
diag = AddDevice()
class MainWindow(QtGui.QMainWindow):
deviceList = []
def openAddDialog(self):
print "running openAddDialog..."
diag = AddDevice()
To copy to clipboard, switch view to plain text mode
from PySide.QtGui import *
def __init__(self):
self.setWindowTitle("Add Device")
self.resize(400, 300)
iLabel
= QLabel("IPv4 address:")
okButton.setText("OK")
okButton.clicked.connect(self.add)
formLayout = QFormLayout(frame)
formLayout.addRow(iLabel, self.iText)
formLayout.addRow(uLabel, self.uText)
formLayout.addRow(pLabel, self.pText)
formLayout.addRow(okButton, okButton)
self.exec_()
def add(self):
ipv4 = self.iText.text()
username = self.uText.text()
password = self.pText.text()
print ipv4, username, password
from PySide.QtGui import *
class AddDevice(QDialog):
def __init__(self):
QDialog.__init__(self)
self.setWindowTitle("Add Device")
self.resize(400, 300)
iLabel = QLabel("IPv4 address:")
self.iText = QLineEdit()
uLabel = QLabel("Username:")
self.uText = QLineEdit()
pLabel = QLabel("Password:")
self.pText = QLineEdit()
okButton = QPushButton()
okButton.setText("OK")
okButton.clicked.connect(self.add)
frame = QFrame(self)
formLayout = QFormLayout(frame)
formLayout.addRow(iLabel, self.iText)
formLayout.addRow(uLabel, self.uText)
formLayout.addRow(pLabel, self.pText)
formLayout.addRow(okButton, okButton)
self.exec_()
def add(self):
ipv4 = self.iText.text()
username = self.uText.text()
password = self.pText.text()
print ipv4, username, password
To copy to clipboard, switch view to plain text mode
Bookmarks