- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我为我的插件创建了一个带有 3 个按钮的启动 GUI。这非常有效,如果我单击其中一个按钮,则会启动一个特定的操作。到目前为止,这是有效的。如果我单击其中一个按钮,则会出现一个带有两个按钮“确定”和“取消”的新 GUI,并且会出现一个 lineedit。如果我按下取消,GUI 将关闭,如果我按下确定,我希望程序从编辑行读取文本并将其存储在一个变量中。到目前为止,这不起作用。
这是包含对话框的类:
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)
这是在使用 QT Designer 和命令 pyuic4 创建 GUI 之后包含 GUI 结构的类:
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))
在这个类中我需要变量:
# 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)
这只是类(class)的一小部分,但这是我对如何从 LineEdit 小部件读取文本有疑问的部分。
您有什么想法或建议吗?
谢谢,如果这是一个双重帖子,我很抱歉,但我还没有找到适合我的问题的答案。
最佳答案
如 documentation 中所述, QLineEdit
的文本可以用它的方法 text
检索。
text = dlg.ui.lineEdit.text()
请注意,它是一个 QString
,而不是一个常规字符串,但是当您使用 "%s"% text
格式化它时,这应该不是问题。
关于python - 如何在 python 中从 QLineEdit 中读出文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12182057/
为什么 naam 输出(NULL)? (抱歉,我知道这是基本的东西,但我是 plist 的新手) 这是plist: 方法如下: - (id) init { self = [super init]; i
我正在使用这个问题的答案中描述的方法向帧缓冲区对象绘制笔触: opengl - blending with previous contents of framebuffer 此方法正确 alpha -
我想将 xml 文件读出到文本 block 中,用户可以在文本 block 中编辑此文本并将附加更改应用回 xml 文件...我目前被卡住了。这是我到目前为止所做的: private void
我需要从我的网络应用程序中的任何 Controller 读出所有可用的操作。这样做的原因是一个授权系统,我需要为用户提供一个允许操作的列表。 例如。: 用户 xyz 具有执行显示、列表、搜索操作的权限
我有一个包含城市区域的 KML 文件,并想用 Javascript 将其读出,以便在 map 上显示这些叠加层(多边形)(Google Maps API v.3)此外,我想从 KML 文件中保存 Ge
我尝试将 onClick 函数从图像复制到 span 对象。但我不明白。 我已经直接使用 onClick=img.onClick、onClick=new Function(img.onClick) 等
我正在考虑使用 Javascript 自动将 border-radius、transform、box-shadow 等 CSS3 属性转换为它们的浏览器特定对应物。 我做了一些研究,发现您可以迭代通过
我有一个关于从 XML 文件读取的问题。 我的 XML 文件: 我的代码: rapidxml::xml_document<> doc; r
我正在为 dwm 构建一个状态栏,我想通过终端读出未读邮件数(使用 grep、sed 或 fopen 作为文件)并通过 fopen/popen 获取它。 我使用的是 ubuntu/dwm/thunde
我尝试用 C# 读出 WMI 数据。我使用 System.Management 命名空间。对于大多数 WMI 查询,它工作得很好。但是,当我尝试从 Win32_PerfFormattedData_Tc
我想使用 Blender 本身的脚本模式读出 Blender 对象的自定义属性。到目前为止,我发现只能读出您在脚本模式下自己创建的自定义属性。但是我想读出我自己标记的自定义属性。这意味着我没有要使用的
我正在尝试读出包含如下数据的文本文件: 1 1 34.5 12.5 1 2 65.3 23.6 1 3 94.3 12.3 依此类推,两个整数后跟两个坐标,冲洗并重复。我使用这段代码(我真的不太懂编程
我想知道如何读出 mp3 歌曲的持续时间。如果我是对的,它不是 ID3 标签,所以我想我必须以某种方式计算它?对于其余的 ID3 标签,我正在使用这个库: http://javamusictag.so
在 iOS 中使用 VoiceOver,当查看分段 Controller 之类的东西时,VoiceOver 会读取分段及其索引,即“已选择:某事:4 之 2”。 我有一个包含几个按钮的自定义 UIVi
我正在尝试从 Microsoft EDGE 浏览器读出标题和 URL。最好使用 System.Windows.Automation 来执行此操作,因为代码库已经使用它来解决其他问题。 可以通过 Sys
从顶部滚动 473 像素后,我有一个显示/隐藏菜单栏。现在我想通了,在其他页面上我需要以不同的 px 偏移量显示/隐藏它(例如,因为顶部的图片更大)。 所以理论上,当我滚动“ anchor ”时,jQ
我是一名优秀的程序员,十分优秀!