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)

相关推荐
OICQQ676580084 天前
创建一个基于YOLOv8+PyQt界面的驾驶员疲劳驾驶检测系统 实现对驾驶员疲劳状态的打哈欠检测,头部下垂 疲劳眼睛检测识别
yolo·pyqt·疲劳驾驶·检测识别·驾驶员检测·打哈欠检测·眼睛疲劳
小灰灰搞电子13 天前
Qt PyQt与PySide技术-C++库的Python绑定
c++·qt·pyqt
越甲八千14 天前
pyqt 简单条码系统
数据库·microsoft·pyqt
重生之我在厦门做测试16 天前
基于pyqt开发串口和对应映射值(path)的显示工具
pyqt
hvinsion19 天前
【开源解析】基于Python+Qt打造智能应用时长统计工具 - 你的数字生活分析师
python·pyqt·开源软件·应用时长统计
毕设做完了吗?21 天前
基于YOLOv8+Deepface的人脸检测与识别系统
python·yolo·毕业设计·pyqt
懷淰メ1 个月前
python3GUI--基于PyQt5+DeepSort+YOLOv8智能人员入侵检测系统(详细图文介绍)
开发语言·深度学习·yolo·目标检测·pyqt·课程设计·deepsort
Humbunklung1 个月前
PySide6 GUI 学习笔记——常用类及控件使用方法(多行文本控件QTextEdit)
笔记·python·学习·pyqt
En^_^Joy1 个月前
PyQt常用控件的使用:QFileDialog、QMessageBox、QTreeWidget、QRadioButton等
开发语言·python·pyqt
zhlei_123451 个月前
封闭内网安装配置VSCode Anconda3 并配置 PyQt5开发
ide·vscode·pyqt