Python 自动完成后将光标移到起始位置

Python 自动完成后将光标移到起始位置,python,pyqt,qlineedit,qcompleter,Python,Pyqt,Qlineedit,Qcompleter,我有一个小程序,其中我使用了自动完成行编辑。选择文本后,我的光标转到文本的末尾。那么如何将光标设置到起始位置呢 我的代码: import sys from PyQt4.QtCore import Qt from PyQt4.QtGui import QApplication, QCompleter, QLineEdit, QStringListModel def get_data(model): model.setStringList(["completion_xxxxxxxxxx",

我有一个小程序,其中我使用了自动完成行编辑。选择文本后,我的光标转到文本的末尾。那么如何将光标设置到起始位置呢

我的代码:

import sys
from PyQt4.QtCore import Qt
from PyQt4.QtGui import QApplication, QCompleter, QLineEdit, QStringListModel

def get_data(model):
   model.setStringList(["completion_xxxxxxxxxx", "data_yyyyyyyyyy", "goes_ccccccccc", "here"])

if __name__ == "__main__":

    app = QApplication(sys.argv)
    edit = QLineEdit()
    edit.setCursorPosition(0)
    completer = QCompleter()
    edit.setCompleter(completer)

    model = QStringListModel()
    completer.setModel(model)
    get_data(model)

    edit.show()
    sys.exit(app.exec_())

但我想这样展示:

completer.activated.connect(
    lambda: QTimer.singleShot(0, lambda: edit.home(False)))

假设您希望光标在完成后移动,您可以将完成器的
激活信号与单次触发计时器一起使用,如下所示:

completer.activated.connect(
    lambda: QTimer.singleShot(0, lambda: edit.home(False)))

非常感谢您的回复,我还有一个疑问可以问吗?我想删除表格小部件中边框的特定单元格,我尝试了很多方法。有一些方法可以删除完整的边框,但我没有找到任何方法来删除表格小部件中边框的特定行,如果您知道的话,请告诉我。@gowthami先生,我在stack overflow中问了很多次,但没有人给出答案,但在我的项目中,我需要这个主题。谢谢YOU@gowthami我看了,但是我看不到关于这个话题的。你指的是哪一个?