I created an initial three-button GUI for my plugin. This works very well, and if I click on one of the buttons, a specific action will begin. While this is working. If I click on one of the buttons, a new graphical interface will appear with two buttons "ok" and "cancel" and the lineedit line will appear. If I click cancel, the GUI will be closed; if I click OK, I want the program to read the text from the edited line and save it in a variable. This does not work so far.
Here is the class containing the dialog:
from PyQt4.QtCore import pyqtSlot
from PyQt4.QtGui import QDialog, QLineEdit
from ui_grz import Ui_Dialog
class grzDialog(QDialog):
def __init__(self):
QDialog.__init__(self)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
This is the class that binds the GUI structure after creating the GUI with QT Designer and the pyuic4 command:
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(387, 153)
self.buttonBox = QtGui.QDialogButtonBox(Dialog)
self.buttonBox.setGeometry(QtCore.QRect(30, 110, 341, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.label = QtGui.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(10, 10, 361, 51))
self.label.setObjectName(_fromUtf8("label"))
self.lineEdit = QtGui.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(10, 60, 351, 31))
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.retranslateUi(Dialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), Dialog.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.reject)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "GRZ Analyse", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("Dialog", "<html><head/><body><p><span style=\" font-weight:600;\">Bitte geben Sie hier den Schwellenwert für die GRZ-Analyse ein:</span></p><p>Bitte achten Sie auf eine korrekte Schreibweise (bspw. 2.5):</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
And in this class I need a variable:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from ubgrzdialog import grzDialog
class quickAnalysis:
def __init__(self, iface):
self.iface = iface
def grzAnalysis(self):
dlg = grzDialog()
dlg.show()
result = dlg.exec_()
if result == 1:
text = dlg.text()
QMessageBox.information(self.iface.mainWindow(),"test", "%s" %(text), QMessageBox.Ok)
, , , LineEdit.
- ?
, , .