Pyqt常用代码片段

MVC

python 复制代码
class Widget(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = Ui_Widget()
        self.ui.setupUi(self)
        self.ui.testButton.clicked.connect(self.button_click)

    def button_click(self):
        global n_page
        pages = [self.ui.page, self.ui.page_2, self.ui.page_3]
        if n_page >= len(pages):
            n_page = 0
        print("Button Active %s Pages: %d" % (self.ui.testButton.objectName(), n_page))
        self.ui.stackedWidget.setCurrentWidget(pages[n_page])
        n_page += 1

    # Mouse event deal functions
    def mousePressEvent(self, event):
        if event.buttons() == Qt.LeftButton:
            print('Mouse click: LEFT CLICK')
        if event.buttons() == Qt.RightButton:
            print('Mouse click: RIGHT CLICK')
python 复制代码
CONFIG_ROOT = QDir.currentPath()
class Widget(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = Ui_Widget()
        self.ui.setupUi(self)
        self.TreeViewMod()

    def TreeViewMod(self):
        TreeModule = QFileSystemModel()
        TreeModule.setRootPath(CONFIG_ROOT)
        self.ui.treeView.setModel(TreeModule)
        self.ui.listView.setModel(TreeModule)
        self.ui.tableView.setModel(TreeModule)

自定义代理类

python 复制代码
from PySide6.QtWidgets import QStyledItemDelegate,QLineEdit,QWidget,QStyleOptionViewItem
from PySide6.QtCore import Qt,QModelIndex,QPersistentModelIndex,QAbstractItemModel

class LineEditDelegate(QStyledItemDelegate):
    def __init__(self,parent=None):
        super().__init__(parent)
    
    def createEditor(self, parent: QWidget, option: QStyleOptionViewItem, index: QModelIndex | QPersistentModelIndex) -> QWidget:
        editor=QLineEdit(parent)
        editor.setFrame(False)
        return editor
    
    def setEditorData(self, editor: QWidget, index: QModelIndex | QPersistentModelIndex) -> None:
        model=index.model()
        text=model.data(index,Qt.ItemDataRole.EditRole)
        editor.setText(text)
    
    def setModelData(self, editor: QWidget, model: QAbstractItemModel, index: QModelIndex | QPersistentModelIndex) -> None:
        text = editor.text()
        model.setData(index,text,Qt.ItemDataRole.EditRole)

    def updateEditorGeometry(self, editor: QWidget, option: QStyleOptionViewItem, index: QModelIndex | QPersistentModelIndex) -> None:
        editor.setGeometry(0,1,2,3)

工具集

python 中使用的 装饰器

c(11)

Rust trait

C++ trait (c20)

windows 常用的进程间的通信就是消息队列
之后会有C++ 20 去写一个客户端的请求程序,和一个微型的服务程序,用于制作一个小网管,PyQt 用于 MVC
简易的一问一答的模式(http 的 post 和 get 请求,优先使用python 解析分析,这部分工作已经完成,原始CGI 的请求访问,以后也会逐步的淘汰),先用简单的方式完成,3种模式(工厂,调试,和维护)
C++ libevent 用于 服务代理和报文解析
Rust(带着看吧,感觉小作坊能用起来的几率太低,但是底层编程的走向,更趋向于用Rust)

相关推荐
爱码小白13 小时前
排除LhPyQt5疑难bug的经验
python·pyqt
懷淰メ2 天前
【AI加持】基于PyQt+YOLO+DeepSeek的安全帽检测系统(详细介绍)
yolo·目标检测·计算机视觉·pyqt·安全帽检测·deepseek·安全帽
懷淰メ2 天前
【AI加持】基于PyQt+YOLO+DeepSeek的PCB缺陷检测系统(详细介绍)
yolo·计算机视觉·pyqt·缺陷检测·pcb·检测系统·pcb缺陷
懷淰メ2 天前
【AI加持】基于PyQt+YOLO+DeepSeek的布匹缺陷检测系统(详细介绍)
yolo·目标检测·计算机视觉·pyqt·缺陷检测·布匹·布匹缺陷
深蓝海拓3 天前
基于QtPy (PySide6) 的PLC-HMI工程项目(十二)最后的工作
网络·笔记·python·学习·pyqt·plc
TOOLS指南4 天前
Python-PyQt界面开发入门-计算器例子
pyqt
小灰灰搞电子4 天前
PyQt QDarkStyle详解-打造专业暗黑界面的瑞士军刀
pyqt·暗黑主题
懷淰メ5 天前
【AI加持】基于PyQt+YOLO+DeepSeek的车型检测系统(详细介绍)
yolo·目标检测·计算机视觉·pyqt·项目设计·deepseek·车型检测
淮北4947 天前
ubuntu22.04将mp4转换成gif
python·scrapy·flask·beautifulsoup·pyqt·matplotlib
懷淰メ7 天前
【AI加持】基于PyQt+YOLO+DeepSeek的口罩佩戴检测系统(详细介绍)
yolo·计算机视觉·pyqt·口罩检测·deepseek·ai加持