PyQt学习笔记:使用QListWidget的findItems方法查找指定项

355 篇文章 47 订阅 ¥49.90 ¥99.00

PyQt学习笔记:使用QListWidget的findItems方法查找指定项

QListWidget是一个非常实用的窗口控件,它可以用来显示和编辑一个简单的列表。在这个列表中,项通常是由文本构成的。当列表中的项太多时,可能会需要查找某个特定的项,使得用户能够更快地找到自己想要的内容。QListWidget提供了一个名为findItems()的方法来完成这项功能。

QListWidget.findItems()方法的语法

findItems(text, flags)
  • text: 要查找的项的文本。
  • flags: 匹配标志,可以是Qt.MatchExactly,Qt.MatchWildcard,Qt.MatchFixedString,Qt.MatchContains,Qt.MatchStartsWith或Qt.MatchEndsWith之一。

QListWidget.findItems()方法的返回值

findItems()方法返回包含匹配的项的列表,如果没有匹配的项,则返回一个空列表。

代码示例

下面是一个简单的代码示例,展示如何使用QListWidget的findItems()方法来查找指定的项。

import sys
from PyQt5.QtWidgets 
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
本片文章的代码#include "chatwindow.h" #include "ui_chatwindow.h" #include #include #include #include #include #include #include ChatWindow::ChatWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::ChatWindow) { ui->setupUi(this); destIP = "255.255.255.0"; destport=8888; udpSocket = new QUdpSocket(this); bool ok = udpSocket->bind(8888); if(!ok){ qDebug() << "Fail to bind port:8888 , error:" <errorString(); return; } connect(udpSocket,SIGNAL(readyRead()),this,SLOT(recvMessage())); } ChatWindow::~ChatWindow() { delete ui; } void ChatWindow::processTheDatagram(const QByteArray &data;,const QHostAddress &sender;, const int senderPort) { //将我们的接收到的json包借读根据不同的message_type值来选择相应的类容 QJsonParseError parseError; qDebug()<<senderPort; QJsonDocument jsondoc = QJsonDocument::fromJson(data,&parseError;); if(jsondoc.isNull() || parseError.error != QJsonParseError::NoError){ qDebug() << "Fail to parse json data : " << parseError.errorString(); return; } QJsonObject jsonObject = jsondoc.object(); int message_type = jsonObject["message_type"].toInt(); QString name = jsonObject["name"].toString(); QString content = jsonObject["content"].toString(); short port = (short)jsonObject["port"].toInt(); switch(message_type){ case ChatWindow::LOGIN_MESSAGE: //添加登陆的用户到好友列表 //给登陆的用户发送一个应答消息,告诉他自己在线 doUserLogin(QHostAddress(sender.toIPv4Address()),name,port); break; case ChatWindow::CHAT_MESSAGE: //显示聊天的消息 break; case ChatWindow::ACK_MESSAGE: //添加应答用户到好友列表 doUserAck(QHostAddress(sender.toIPv4Address()),name,port); return; case ChatWindow::QUIT_MESSAGE: //将退出的用户从好友列表中删除 doUserQuit(QHostAddres

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值