1、为了让菜单选项和工具栏在用户点击它们时启动,需要将信号与内置插槽连接起来。
2、QAction物体可以发出各种信号。triggered()与插槽连接。
菜单和工具栏中最常用的信号是.triggered()。用户每次点击菜单选项或工具栏按钮都会发出这个信号。
实例
class Window(QMainWindow): # Snip... def newFile(self): # Logic for creating a new file goes here... self.centralWidget.setText("File > New clicked") def openFile(self): # Logic for opening an existing file goes here... self.centralWidget.setText("File > Open... clicked") def saveFile(self): # Logic for saving a file goes here... self.centralWidget.setText("File > Save clicked") def copyContent(self): # Logic for copying content goes here... self.centralWidget.setText("Edit > Copy clicked") def pasteContent(self): # Logic for pasting content goes here... self.centralWidget.setText("Edit > Paste clicked") def cutContent(self): # Logic for cutting content goes here... self.centralWidget.setText("Edit > Cut clicked") def helpContent(self): # Logic for launching help goes here... self.centralWidget.setText("Help > Help Content... clicked") def about(self): # Logic for showing an about dialog content goes here... self.centralWidget.setText("Help > About... clicked")
以上就是python PyQt信号和插槽的连接方法,希望对大家有所帮助。更多Python学习指路:创新互联python教程
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
网站栏目:创新互联Python教程:python PyQt信号和插槽的连接
当前网址:http://www.shufengxianlan.com/qtweb/news21/467171.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联