3 개의 버튼이있는 시작 GUI를 내 플러그인 용으로 만들었습니다. 이것은 매우 잘 작동하며 버튼 중 하나를 클릭하면 특정 작업이 시작됩니다. 지금까지이 작품. 버튼 중 하나를 클릭하면 "ok"와 "cancel"두 개의 버튼과 라인 수정이있는 새로운 GUI가 나타납니다. 취소를 계속하면 GUI가 닫히고, 확인을 누르면 프로그램이 편집 라인의 텍스트를 읽고 변수에 저장합니다. 이것은 지금까지 작동하지 않습니다.QLineEdit에서 파이썬으로 텍스트를 읽는 방법은 무엇입니까?
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))
그리고 :이 QT 디자이너와 GUI 및 명령 pyuic4을 만든 후 GUI의 구조를 contians 클래스가
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)
# Set up the user interface from Designer.
self.ui = Ui_Dialog()
self.ui.setupUi(self)
: 여기
대화 상자를 포함하는 클래스입니다 이 클래스에서 변수가 필요합니다.# Import the PyQt and QGIS libraries
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
# Import the code for the dialog
from ubgrzdialog import grzDialog
class quickAnalysis:
def __init__(self, iface):
# Save reference to the QGIS interface
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 위젯에서 텍스트를 읽는 방법에 대해 질문하는 부분입니다.
의견이나 제안이 있으십니까?
두 번 게시물인데 죄송하지만 내 문제에 대해 적절한 답변을 찾지 못했습니다.
이것은 작동합니다. 감사! – Sven