如何删除 QLineedit completer 中的光标
how to remove the cursor in QLineedit completer
这是我的 Qlineedit Completer 示例程序。在 Autosuggestion 之后,我想在我写的 completer.activated.connect(lambda: QTimer.singleShot(0, lambda: edit.home(False)))
的行编辑中将文本显示为项目的开头。它工作正常,但我不想在自动暗示后的乞讨和最后显示光标。
下面是我的代码:
import sys
from PyQt4.QtCore import Qt,QTimer
from PyQt4.QtGui import QApplication, QCompleter, QLineEdit, QStringListModel
def get_data(model):
model.setStringList(["completionProgramxxxxxxxxxxxxxxx", "completionProgramyyyyyy","truthordisabled", "storecredit", "iamhere"])
if __name__ == "__main__":
app = QApplication(sys.argv)
edit = QLineEdit()
completer = QCompleter()
edit.setCompleter(completer)
completer.activated.connect(lambda: QTimer.singleShot(0, lambda: edit.home(False)))
model = QStringListModel()
completer.setModel(model)
get_data(model)
edit.show()
sys.exit(app.exec_())
我得到的图像是这样的:
你要清理焦点:
import sys
from PyQt4 import QtCore, QtGui
def get_data(model):
model.setStringList(
[
"completionProgramxxxxxxxxxxxxxxx",
"completionProgramyyyyyy",
"truthordisabled",
"storecredit",
"iamhere",
]
)
class Completer(QtGui.QCompleter):
def __init__(self, parent=None):
super(Completer, self).__init__(parent)
self.activated.connect(self.on_activated)
@QtCore.pyqtSlot()
def on_activated(self):
le = self.widget()
if isinstance(le, QtGui.QLineEdit):
le.home(False)
le.clearFocus()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
edit = QtGui.QLineEdit()
completer = Completer(edit)
edit.setCompleter(completer)
model = QtGui.QStringListModel(edit)
completer.setModel(model)
get_data(model)
edit.show()
sys.exit(app.exec_())
这是我的 Qlineedit Completer 示例程序。在 Autosuggestion 之后,我想在我写的 completer.activated.connect(lambda: QTimer.singleShot(0, lambda: edit.home(False)))
的行编辑中将文本显示为项目的开头。它工作正常,但我不想在自动暗示后的乞讨和最后显示光标。
下面是我的代码:
import sys
from PyQt4.QtCore import Qt,QTimer
from PyQt4.QtGui import QApplication, QCompleter, QLineEdit, QStringListModel
def get_data(model):
model.setStringList(["completionProgramxxxxxxxxxxxxxxx", "completionProgramyyyyyy","truthordisabled", "storecredit", "iamhere"])
if __name__ == "__main__":
app = QApplication(sys.argv)
edit = QLineEdit()
completer = QCompleter()
edit.setCompleter(completer)
completer.activated.connect(lambda: QTimer.singleShot(0, lambda: edit.home(False)))
model = QStringListModel()
completer.setModel(model)
get_data(model)
edit.show()
sys.exit(app.exec_())
我得到的图像是这样的:
你要清理焦点:
import sys
from PyQt4 import QtCore, QtGui
def get_data(model):
model.setStringList(
[
"completionProgramxxxxxxxxxxxxxxx",
"completionProgramyyyyyy",
"truthordisabled",
"storecredit",
"iamhere",
]
)
class Completer(QtGui.QCompleter):
def __init__(self, parent=None):
super(Completer, self).__init__(parent)
self.activated.connect(self.on_activated)
@QtCore.pyqtSlot()
def on_activated(self):
le = self.widget()
if isinstance(le, QtGui.QLineEdit):
le.home(False)
le.clearFocus()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
edit = QtGui.QLineEdit()
completer = Completer(edit)
edit.setCompleter(completer)
model = QtGui.QStringListModel(edit)
completer.setModel(model)
get_data(model)
edit.show()
sys.exit(app.exec_())