PyQt的signal 和 solit的补充

简介:   from PyQt5.QtWidgets import (QWidget , QVBoxLayout , QHBoxLayout, QLineEdit, QPushButton) from PyQt5.

 

 

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_())

  

 

相关文章
|
2月前
|
机器学习/深度学习 算法 Linux
Yolov5水果分类识别+pyqt交互式界面
Yolov5水果分类识别+pyqt交互式界面
72 1
|
3月前
|
开发框架 开发者 Python
探索Python GUI编程:从Tkinter到PyQt的全方位使用
在当今技术发展日新月异的时代,Python作为一种简洁高效的编程语言,拥有广泛的应用领域。其中,GUI(图形用户界面)编程是Python开发者经常涉足的领域之一。本文将介绍两个常用的Python GUI库——Tkinter和PyQt,并深入探讨其使用方法、特点以及适用场景,帮助读者全面了解Python GUI编程的魅力。
|
3月前
|
Python
PyQt绘制股票K线多图Y坐标对齐
PyQt绘制股票K线多图Y坐标对齐
48 0
|
5月前
|
Python
pyqt 重写关闭窗口事件代码
pyqt 重写关闭窗口事件代码
39 0
|
3月前
|
数据可视化 Linux C++
Python GUI编程:Tkinter与PyQt的选择
Python作为一门流行的编程语言,在GUI编程领域也有着非常强大的工具。其中,Tkinter和PyQt是两个备受推崇的GUI库。本文将介绍这两个库的优缺点,并帮助读者决定应该选择哪一个。
57 0
|
3月前
|
前端开发 Python
【Python • 项目实战】pytesseract+pyqt实现图片识别软件小项目——(二)实现QQ截图功能
【Python • 项目实战】pytesseract+pyqt实现图片识别软件小项目——(二)实现QQ截图功能
62 0
|
2月前
|
数据可视化 API 开发者
Python中的图形界面开发:Tkinter、PyQt或wxPython入门
Python中的图形界面开发:Tkinter、PyQt或wxPython入门
|
3月前
|
Python
Python GUI编程的两种选择:Tkinter与PyQt
Python作为一门流行的编程语言,其GUI编程也备受关注。在GUI编程中,Tkinter和PyQt是两种常见的选择。本文将从简介、使用、优缺点等多个方面对比这两种框架,以帮助读者选择适合自己的工具。
|
4月前
|
程序员 API Python
PyQt
PyQt 是一个用于创建桌面应用程序的 Python 库,它提供了大量的 GUI 控件和工具,使 Python 程序员可以快速地开发出具有良好用户界面的应用程序。PyQt 支持两种不同的用户界面风格:Qt4 和 Qt5。PyQt4 是基于 Qt4 库的,而 PyQt5 是基于 Qt5 库的。PyQt5 是目前最先进的版本,推荐使用。 使用 PyQt 开发应用程序的步骤如下:
56 10
|
5月前
|
Python
pyqt 创建系统托盘
pyqt 创建系统托盘
42 0

热门文章

最新文章