惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
S
Secure Thoughts
S
Schneier on Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Cyberwarzone
Cyberwarzone
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Privacy International News Feed
L
Lohrmann on Cybersecurity
Schneier on Security
Schneier on Security
PCI Perspectives
PCI Perspectives
Google DeepMind News
Google DeepMind News
C
Cybersecurity and Infrastructure Security Agency CISA
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Latest news
Latest news
H
Hacker News: Front Page
月光博客
月光博客
Forbes - Security
Forbes - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
WordPress大学
WordPress大学
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
宝玉的分享
宝玉的分享
D
Docker
U
Unit 42
Recorded Future
Recorded Future
Spread Privacy
Spread Privacy
Microsoft Security Blog
Microsoft Security Blog
Recent Announcements
Recent Announcements
云风的 BLOG
云风的 BLOG
Application and Cybersecurity Blog
Application and Cybersecurity Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Heimdal Security Blog
Microsoft Azure Blog
Microsoft Azure Blog
V
Vulnerabilities – Threatpost
Vercel News
Vercel News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
L
LangChain Blog
G
GRAHAM CLULEY
Apple Machine Learning Research
Apple Machine Learning Research
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Blog — PlanetScale
Blog — PlanetScale
博客园 - 三生石上(FineUI控件)
罗磊的独立博客
Help Net Security
Help Net Security
Google Online Security Blog
Google Online Security Blog
S
SegmentFault 最新的问题

WMI

How to Activate MySQL for Multiple Devices - WMI ESLint Flat Config for JS, TS, React, and Prettier - WMI Yarn NPM Registry Configuration - WMI Yarn Guides - WMI Set Up ADB Wireless Debugging on Android: A Full Guide - WMI How to Fill Tax Information on Google Adsense - WMI Migrate ESLint v9 for prettier typescript javascript - WMI PySide6 button click open new window - WMI Mobile Legends To The Stars Event Clue - WMI [PHP] generate random proxy IP:PORT from CIDR - WMI [PHP] generate big text file for testing purpose - WMI List of Chrome Driver command line arguments - WMI Happy eid mubarak - WMI Install markdown engine on vite ESM typescript - WMI Android Activity lifecycle - WMI OkHttp cookie handling on android (webview supported) - WMI Turn git log history into markdown - WMI enable automatic memory heap resizing of android studio - WMI is defining screen density can reduce build time ? - WMI
PySide6 autocomplete input text - WMI
Dimas Lanjaka · 2024-08-17 · via WMI

Sample App

sample PySide6 application with autocomplete functionality using QLineEdit and QCompleter. This example creates a simple window with a text input field that provides autocomplete suggestions as the user types.

from PySide6.QtWidgets import QApplication, QMainWindow, QLineEdit, QCompleter, QVBoxLayout, QWidget
from PySide6.QtCore import QStringListModel

class AutocompleteApp(QMainWindow):
    def __init__(self):
        super().__init__()

        # Set up the main window
        self.setWindowTitle("Autocomplete Example")
        self.setGeometry(100, 100, 400, 200)

        # Create a central widget and a layout
        central_widget = QWidget()
        layout = QVBoxLayout()

        # Create QLineEdit widget
        self.line_edit = QLineEdit()
        self.line_edit.setPlaceholderText("Type something...")

        # Create sample data for autocomplete
        data = ["apple", "banana", "grape", "orange", "peach", "pear", "plum"]

        # Create QStringListModel and QCompleter
        self.model = QStringListModel(data)
        self.completer = QCompleter(self.model)
        self.line_edit.setCompleter(self.completer)

        # Add the QLineEdit to the layout
        layout.addWidget(self.line_edit)
        central_widget.setLayout(layout)
        self.setCentralWidget(central_widget)

if __name__ == "__main__":
    app = QApplication([])
    window = AutocompleteApp()
    window.show()
    app.exec()

Explanation:

  1. AutocompleteApp Class: This class extends QMainWindow to create the main application window.
  2. __init__ Method: Sets up the window title, size, and central widget.
  3. QLineEdit: A text input field where users type text.
  4. QStringListModel: Holds the list of strings that will be used for autocomplete suggestions.
  5. QCompleter: Provides the autocomplete functionality using the QStringListModel.
  6. Layout: Uses QVBoxLayout to arrange the QLineEdit within the main window.

To run this application, save the code to a file (e.g., autocomplete_app.py) and execute it with Python. Make sure you have PySide6 installed in your environment.

Helper

PySide6 set QLineEdit autocomplete helper

from PySide6.QtWidgets import QLineEdit, QCompleter
from PySide6.QtCore import QStringListModel
from typing import List

def set_completer(line_edit: QLineEdit, data: List[str]) -> None:
    """
    Configures a QLineEdit widget with a QCompleter for autocomplete functionality.

    Args:
        line_edit (QLineEdit): The QLineEdit widget to which the completer will be applied.
        data (List[str]): A list of strings to be used as autocomplete suggestions.

    Returns:
        None
    """
    # Create a QStringListModel with the provided data
    model = QStringListModel(data)

    # Create a QCompleter with the model
    completer = QCompleter(model)

    # Set the completer on the QLineEdit
    line_edit.setCompleter(completer)