【发布时间】:2018-01-18 23:44:25
【问题描述】:
我正在使用 USB 条形码扫描仪来设置 Qt lineEdit 字段的文本,然后将其文本用于 GUI 的其他功能(具体来说,文本是当前正在运行的示例的名称由用户测量,稍后将保存为文件名)。
我的问题是我想用下一个扫描的barcode 动态覆盖lineEdit 字段中的当前文本,而不用户必须在扫描前手动删除当前文本。因为我只是将扫描仪用作键盘仿真器,而不是从中正确读取串行信息,所以用户必须在扫描前单击文本字段。
我不知道哪个lineEdit 连接操作允许以下操作:
from PyQt4 import QtGui
# add widgets etc
# ...........
# lineEdit part
self.mylineEdit = QtGui.QLineEdit()
#initialise to empty string on start up
self.mylineEdit.setText(' ')
#barcode scans here and then a returnPressed is registered
#connect to a function
self.mylineEdit.returnPressed.connect(self.set_sample_name) #here is where I want to delete the previous entry without backspacing by hand
#set the sample name variable
def set_sample_name(self):
self.sample_name = self.mylindEdit.text()
我想知道有没有办法在扫描下一个barcode 之前删除文本框中的前一个字符串? (文本字段暂时没有变空)..
谢谢。
PS - 在 Ubuntu 16.04 上使用 python3.5.2 和 pyQT4
【问题讨论】:
-
您可以使用 mylineEdit.setFocus() 切换到 lineEdit 并覆盖我正在上传答案的上一个字符串
标签: python qt pyqt barcode-scanner