Python Qcompleter currentCompletion不工作
最近,我正在做一个代码完成演示。我想创建与弹出窗口()中的项目关联的工具提示。当用户在弹出列表视图中选择一个项目时,工具提示将显示与之关联的项目所查询的某些信息。我尝试了currentCompletion()来获取项目内容,它只返回了第一次完成。如何解决这个问题 这是我的申请表Python Qcompleter currentCompletion不工作,python,pyqt,pyqt5,qcompleter,Python,Pyqt,Pyqt5,Qcompleter,最近,我正在做一个代码完成演示。我想创建与弹出窗口()中的项目关联的工具提示。当用户在弹出列表视图中选择一个项目时,工具提示将显示与之关联的项目所查询的某些信息。我尝试了currentCompletion()来获取项目内容,它只返回了第一次完成。如何解决这个问题 这是我的申请表 from PyQt5.QtCore import * from PyQt5.QtWidgets import * from PyQt5.QtGui import * def get_data(model): # Se
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
def get_data(model):
# Searching through the Doc
# Result shows in a dictionary structure
result = {"alpha": 0, "apple": 1, "agree": 2}
icon_address = ['..\..\Src\Img\A.png', '..\..\Src\Img\E.png','..\..\Src\Img\O.png']
for cmd, value in result.items():
item = QStandardItem(cmd)
item.setIcon(QIcon(icon_address[value]))
model.insertRow(0, item)
class CodeAC:
def __init__(self, input_line):
self.completer = QCompleter()
input_line.setCompleter(self.completer)
self.model = QStandardItemModel()
def active_script(self):
get_data(self.model)
self.completer.setModel(self.model)
def tip_balloon(self):
key = self.completer.currentRow()
print(key)
以下是我的主要观点:
from Src.Extention.src.code_ac import *
import sys
import ctypes
class MainWindow(QWidget):
def __init__(self):
super(MainWindow, self).__init__()
self.extention = None
self.entry = QLineEdit(self)
def init_main(self):
self.setGeometry(600,600,800,600)
self.setWindowTitle('VISA Communication')
self.setWindowIcon(QIcon('..\..\Src\Img\icon.png'))
self.show()
def active_extention(self):
self.extention = CodeAC(self.entry)
self.extention.active_script()
if __name__ == '__main__':
app = QApplication(sys.argv)
root = MainWindow()
root.init_main()
root.active_extention()
sys.exit(app.exec_())
打印只给0,即使我选择第二次完成。这是屏幕截图
您必须使用
QCompleter
的激活的信号,并修改提示气泡:
[...]
self.completer.setModel(self.model)
self.completer.activated.connect(self.tip_balloon)
def tip_balloon(self, text):
print(text)
您必须使用QCompleter
的activated
信号并修改提示气球:
[...]
self.completer.setModel(self.model)
self.completer.activated.connect(self.tip_balloon)
def tip_balloon(self, text):
print(text)
我在活动脚本函数中调用了self.extention.tip\u ballon(),在活动脚本函数中调用了self.extention.tip\u ballon(),它可以工作!这真的很有帮助。谢谢你,埃伦斯克。顺便问一下,有适合初学者的PyQt教程吗?阅读文档对我来说真的很痛苦。作为一名开发人员,你必须学会阅读文档,祝你好运:PIt工作!这真的很有帮助。谢谢你,埃伦斯克。顺便问一下,有适合初学者的PyQt教程吗?阅读文档对我来说真的很痛苦。作为一名开发人员,你必须学会阅读文档,祝你好运:P