pyqt5 python qlineedit信号_PyQt5 文本输入框自动补全QLineEdit的实现示例

一、QCompleter类自动补全会用到的一个类主要代码def init_lineedit(self):# 增加自动补全self.completer = QCompleter(items_list)# 设置匹配模式 有三种: Qt.MatchStartsWith 开头匹配(默认) Qt.MatchContains 内容匹配 Qt.MatchEndsWith 结尾匹配self.completer.s...
摘要由CSDN通过智能技术生成

一、QCompleter类

自动补全会用到的一个类

主要代码

def init_lineedit(self):

# 增加自动补全

self.completer = QCompleter(items_list)

# 设置匹配模式 有三种: Qt.MatchStartsWith 开头匹配(默认) Qt.MatchContains 内容匹配 Qt.MatchEndsWith 结尾匹配

self.completer.setFilterMode(Qt.MatchContains)

# 设置补全模式 有三种: QCompleter.PopupCompletion(默认) QCompleter.InlineCompletion QCompleter.UnfilteredPopupCompletion

self.completer.setCompletionMode(QCompleter.PopupCompletion)

# 给lineedit设置补全器

self.lineedit.setCompleter(self.completer)

def init_combobox(self):

# 增加选项元素

for i in range(len(items_list)):

self.combobox.addItem(items_list[i])

self.combobox.setCurrentIndex(-1)

# 增加自动补全

self.completer = QCompleter(items_list)

self.completer.setFilterMode(Qt.MatchContains)

self.completer.setCompletionMode(QCompleter.PopupCompletion)

self.combobox.setCompleter(self.completer)

完整代码:

import sys

from PyQt5.QtWidgets import *

from PyQt5.QtGui import *

from PyQt5.QtCore import *

################################################

items_list=["C","C++","Java","Python","JavaScript","C#","Swift","go","Ruby","Lua","PHP"]

################################################

class Widget(QWidget):

def __init__(self, *args, **kwargs):

super(Widget, self).__init__(*args, **kwargs)

layout = QHBoxLayout(self)

self.lineedit = QLineEdit(self, minimumWidth=200)

self.combobox = QComboBox(self, minimumWidth=200)

self.combobox.setEditable(True)

layout.addWidget(QLabel("QLineEdit", self))

layout.addWidget(self.lineedit)

layout.addItem(QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum))

layout.addWidget(QLabel("QComboBox", self))

layout.addWidget(self.combobox)

#初始化combobox

self.init_li

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值