博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PyQt4 / PyQt5
阅读量:6767 次
发布时间:2019-06-26

本文共 4072 字,大约阅读时间需要 13 分钟。

Python事多,做个笔记,区分。

 

PyQt5 Reference Guide

http://pyqt.sourceforge.net/Docs/PyQt5/index.html

 

Qt4 signal:

class CopyFileThread(QtCore.QThread):    signal_process = QtCore.pyqtSignal(str, str, bool)    def __init__(self, parent=None):        super(CopyFileThread, self).__init__(parent)        self.finished.connect(self.taskEnd)    def setSourceAndDestination(self, src, des):        self.source = src        self.des = des        self.status = False    def run(self):        #print "copy -> ", self.source, self.des        # QtCore.QFile.copy(self.source,self.des)        try:            shutil.copy(self.source, self.des)            self.status = True        except:            self.status = False    def taskEnd(self):        self.signal_process.emit(self.source, self.des, self.status)
View Code

接受这个signal槽:

@QtCore.pyqtSlot(str, str, bool)    def perThreadCopyEnd(self, src, des, status):        self.taskNum += 1        if (status):            self.throwMessage(">>" + src + "\t->->->->\t" + des + "<
>" + src + "\tT_T T_T T_T\t" + des + "<
> process end")
View Code

 

Qt5展示的一些发射信号:

from PyQt5.QtCore import QObject, pyqtSignalclass Foo(QObject):    # Define a new signal called 'trigger' that has no arguments.    trigger = pyqtSignal()    def connect_and_emit_trigger(self):        # Connect the trigger signal to a slot.        self.trigger.connect(self.handle_trigger)        # Emit the signal.        self.trigger.emit()    def handle_trigger(self):        # Show that the slot has been called.        print "trigger signal received"
View Code

 

信号重载

from PyQt5.QtWidgets import QComboBoxclass Bar(QComboBox):    def connect_activated(self):        # The PyQt5 documentation will define what the default overload is.        # In this case it is the overload with the single integer argument.        self.activated.connect(self.handle_int)        # For non-default overloads we have to specify which we want to        # connect.  In this case the one with the single string argument.        # (Note that we could also explicitly specify the default if we        # wanted to.)        self.activated[str].connect(self.handle_string)    def handle_int(self, index):        print "activated signal passed integer", index    def handle_string(self, text):        print "activated signal passed QString", text
View Code

 

 QML:

<1> show 一个qml里的window

import QtQuick 2.0import QtQuick.Window 2.2import QtQuick.Controls 1import QtQuick.Dialogs 1.2Window{    id:root    width:1280    height:720    Rectangle    {        id:rec        color:"#FF2020"        width:100        height:100        anchors.centerIn:parent        border.color:"#202020"        border.width:1    }    MouseArea    {        id:quitArea        anchors.fill:        {            rec        }        onClicked:        {            close()        }    }}
View Code

main.py:

from PyQt5 import QtWidgets,QtGui,QtCorefrom PyQt5 import QtQmlfrom PyQt5.QtQuick import QQuickView,QQuickWindowimport sysif __name__ == "__main__":    app = QtGui.QGuiApplication(sys.argv)    eng = QtQml.QQmlApplicationEngine()    eng.load(QtCore.QUrl.fromLocalFile('./UI/main.qml'))    topLevel = eng.rootObjects()[0]    print topLevel    topLevel.show()    app.exec_()

 

创建混合窗口:

 

按钮是QPushButton,下面的白色区域是QtQuickWindow

from PyQt5 import QtWidgets,QtGui,QtCorefrom PyQt5 import QtQmlfrom PyQt5.QtQuick import QQuickView,QQuickWindowimport sysif __name__ == "__main__":    app = QtWidgets.QApplication(sys.argv)    eng = QtQml.QQmlApplicationEngine()    eng.load(QtCore.QUrl.fromLocalFile('./UI/Main.qml'))    topLevel = eng.rootObjects()[0]    print topLevel    #topLevel.show()    layout = QtWidgets.QVBoxLayout()    button = QtWidgets.QPushButton()    button.setText("houdini")    layout.addWidget(button)    mainWidget = QtWidgets.QWidget()    quickWidget = QtWidgets.QWidget.createWindowContainer(topLevel)    #quickWidget.show()    mainWidget.setLayout(layout)    layout.addWidget(quickWidget)    mainWidget.show()    app.exec_()
View Code

 

转载于:https://www.cnblogs.com/gearslogy/p/7805044.html

你可能感兴趣的文章
基于java web开发的一个购物网站
查看>>
FreeGis站位
查看>>
JTBC方便的下拉列表来编辑系统,更方便快捷!
查看>>
Python学习--13 文件I/O
查看>>
Linux od命令
查看>>
java一维数组的冒泡排序
查看>>
对FTP服务器(Serv-U)账户赋权不当造成的安全隐患
查看>>
iOS 多态的简单思想
查看>>
apache不能正常处理ssi文件
查看>>
hive0.13 mapjoin hashtable找不到的bug
查看>>
UVALive 3971 组装电脑
查看>>
我的友情链接
查看>>
三、生成静态页
查看>>
细数IT部在企业中位置的现状和发展
查看>>
我的友情链接
查看>>
Bacula 介绍
查看>>
ubuntu16.04 ,安装最新版本docker
查看>>
设计模式系列-工厂方法模式
查看>>
centos6.2 部分pdf中文文档乱码解决
查看>>
远程桌面登录
查看>>