PyQt的signal 和 solit的补充
from PyQt5.QtWidgets import (QWidget
, QVBoxLayout , QHBoxLayout,
QLineEdit, QPushButton) from PyQt5.QtCore import pyqtSignal
from PyQt5 import QtCore
############################################## # 参考大丸子的博客
#http://jimmykuu.sinaapp.com/blog/11 class LoginView(QWidget): ## 登录界面时发送 关闭信号
quitSignal = pyqtSignal()
loginSignal = pyqtSignal(list)
# server端没有响应
openFailureSignal = pyqtSignal() def __init__(self, parent=None):
super(LoginView, self).__init__(parent)
self.ids_receive = [] self._init_ui() def _init_ui(self): layout_button = QHBoxLayout()
layout_input = QHBoxLayout() self.input_name = QLineEdit()
self.input_pass = QLineEdit() button_login = QPushButton("登录")
button_login.setObjectName("ok_button") button_quit = QPushButton("取消")
button_hello = QPushButton("hello")
self.button_hello = button_hello
button_hello.setObjectName("hello_button") #button_login.clicked.connect(self.do_login)
#button_quit.clicked.connect(self.loginQuit) layout_button.addWidget(button_login)
layout_button.addWidget(button_quit) layout_input.addWidget(self.input_name)
layout_input.addWidget(self.input_pass)
layout_input.addWidget(self.button_hello) layout_main = QVBoxLayout()
self.setLayout(layout_main)
layout_main.addLayout(layout_button)
layout_main.addLayout(layout_input) # QMetaObject. connectSlotsByName(QObject)
#网上百度到的说明:其作用是如其名称一样,用来将QObject 里的子孙QObject的某些信号按照其objectName连接到相应的槽上
# ,如 button_hello.setObjectName("hello_button")
# 官网解释用法: http://doc.qt.io/qt-5/qmetaobject.html#connectSlotsByName
QtCore.QMetaObject.connectSlotsByName(self) def loginQuit(self):
print ("cencel") #试试注销掉该装饰器
# 有点奇怪啊,一旦注释掉装饰器,打印会执行两次啊
#QtCore.pyqtSlot(str, str)可以携带参数的
@QtCore.pyqtSlot()
def on_hello_button_clicked(self):
print('on_pbHello_clicked') @QtCore.pyqtSlot()
def on_ok_button_clicked(self):
print ("OK")
self.loginSignal.emit([1, 2]) def do_login(self):
#获取用户和密码文本框的内容
u_name = self.input_name.text()
u_pass = self.input_pass.text() print('u_name', u_name, u_pass) if __name__ == '__main__': import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv) login = LoginView()
login.show() sys.exit(app.exec_())
PyQt的signal 和 solit的补充的更多相关文章
- 转载:pyqt的signal和solit
转自:http://blog.csdn.net/hlqyq/article/details/6713828 import sysfrom PyQt5.QtCore import pyqtSignal, ...
- JAVA中的枚举小结
枚举 将一组有限集合创建为一种新的类型,集合里面的值可以作为程序组件使用: 枚举基本特性 以下代码是枚举的简单使用: 使用values方法返回enum实例的数组 使用ordinal方法返回每个enum ...
- PyQt信号connect连接槽方法时报:native Qt signal is not callable错误
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 在将一个信号连接到槽方法时,程序异常退出,捕获异常 ...
- 第四章 、PyQt中的信号(signal)和槽(slot)机制以及Designer中的使用
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 一.引言 前面章节其实已经在使用信号和槽了,但是作为Qt中最重要的机制也是Qt区别与其他开发平台的重 ...
- 第15.16节 PyQt(Python+Qt)入门学习:PyQt中的信号(signal)和槽(slot)机制以及Designer中的使用
老猿Python博文目录 老猿Python博客地址 一.引言 前面一些章节其实已经在使用信号和槽了,但是作为Qt中最重要的机制也是Qt区别与其他开发平台的重要核心特性,还是非常有必要单独介绍. 二.信 ...
- Linux 条件变量函数signal和wait补充
pthread_cond_wait必须放在pthread_mutex_lock和pthread_mutex_unlock之间,因为他要根据共享变量的状态来觉得是否要等待,而为了不永远等待下去所以必须要 ...
- pyqt的多Button的点击事件的槽函数的区分发送signal的按钮。
关键函数:QPushButton的setObjectName()/objectName() 个人注解:按功能或者区域,将按钮的点击事件绑定的不同的槽函数上. from PyQt5.QtWidgets ...
- 信号 signal sigaction补充
目前linux中的signal()是通过sigation()函数实现的. 由signal()安装的实时信号支持排队,同样不会丢失. 先看signal 和 sigaction 的区别: 关键是 stru ...
- PyQt学习随笔:QTableWidget的信号signal简介
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QTableWidget非继承自父类的信号如下: cellActivated(int row, in ...
随机推荐
- c++ primer读书笔记之c++11(一)
1 新的关键词nullptr c++11引入新的关键词nullptr,用于表示空指针,用于替换之前c提供的NULL(最初NULL是定义在stdlib中的宏定义,通常是0). 2 新的别名定义机制 al ...
- 域控制器修改IP操作步骤
域控制器更改IP 在DC运维时,可能会碰上需要调整域控制器IP的情况,下面的操作就是在Windows Server 2008环境下域控制器更改IP的完整操作步骤. 1. 使用管理员帐号登录域控制器,依 ...
- SQL 迭代查询语句
SQL迭代查询 PL/SQL with ORG_Tree(ObjectId,parentID) as ( select a.ObjectId,a.parentID from Ot_Organizati ...
- Android开发(六)——组件颜色Selector(Selector与Shape的基本用法 )
andorid控件改变状态时改变颜色,使用selector. <?xml version="1.0" encoding="utf-8" ?> < ...
- Upload文件时出现"Cannot access a closed file"错误
本地能上传文件,部署到服务器上就报 Cannot access a closed file 错误,以下是解决方法: <System.Web> <httpRuntime executi ...
- WebAPI Action的几种返回值类型
void 返回204状态码 HttpResponseMessage Convert directly to an HTTP response message. IHttpActionResult Ca ...
- APMServ5.2.6 升级php5.2 到 5.3版本及Memcache升级!
一.如何选择PHP5.3的VC9版本和VC6版本 VC6是什么?VC6就是legacy Visual Studio 6 compiler,就是使用这个编译器编译的.VC9是什么?VC9就是the V ...
- WPF定义样式文件的方式
场景:一个页面中有两类按钮,分别为样式A和样式B,但是WPF中不能像Web一样定义多个样式 样式定义方法: 1. 一个一个写内联样式 2. 定义样式<style TargetType=" ...
- CPP_类默认函数:构造函数,拷贝构造函数,赋值函数和析构函数
类默认函数:构造函数,拷贝构造函数,赋值函数和析构函数 // person.h #ifndef _PERSON_H_ #define _PERSON_H_ class Person{ public : ...
- Spring Cloud Config 配置中心 自动加解密功能 jasypt方式
使用此种方式会存在一种问题:如果我配置了自动配置刷新,则刷新过后,加密过后的密文无法被解密.具体原因分析,看 SpringCloud 详解配置刷新的原理 使用 jasypt-spring-boot- ...