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)

相关推荐
酷飞飞4 天前
PyQt 界面布局与交互组件使用指南
python·qt·交互·pyqt
qq_340474025 天前
Q3.1 PyQt 中的控件罗列
pyqt
万粉变现经纪人5 天前
如何解决pip安装报错ModuleNotFoundError: No module named ‘sympy’问题
python·beautifulsoup·pandas·scikit-learn·pyqt·pip·scipy
Goona_6 天前
PyQt数字转大写金额GUI工具开发及财务规范实现
python·小程序·交互·pyqt
小叮当⇔6 天前
PYcharm——pyqt音乐播放器
ide·pycharm·pyqt
青铜发条7 天前
【Qt】PyQt、原生QT、PySide6三者的多方面比较
开发语言·qt·pyqt
Goona_8 天前
pyqt+python之二进制生肖占卜
pyqt
大学生毕业题目10 天前
毕业项目推荐:83-基于yolov8/yolov5/yolo11的农作物杂草检测识别系统(Python+卷积神经网络)
人工智能·python·yolo·目标检测·cnn·pyqt·杂草识别
凯子坚持 c14 天前
当Python遇见高德:基于PyQt与JS API构建桌面三维地形图应用实战
javascript·python·pyqt·高德地图