对pyqt5之menu和action的使用详解

yipeiwu_com6年前Python基础

如下所示:

 exitAct = QAction(QIcon('exit.png'), '&Exit', self)    
exitAct.setShortcut('Ctrl+Q')
exitAct.setStatusTip('Exit application')

QAction is an abstraction for actionsperformed with a menubar, toolbar, or with a custom keyboard shortcut.

QAction 模块 :菜单栏或者 工具栏 ,或者自定义热键 后,软件执行的动作。

第一行指定一个实例,并设定名称 和对应的图标。第二行设定快捷键

exitAct.triggered.connect(qApp.quit)
When we select this particular action, a triggered signal is emitted. The signal is connected to the quit() method of theQApplication widget. This terminates the application.

当选择上述定义的实例后,triggered 信号产生,此信号和qApp.quit相关联,也可以和其他方法相关联。

将上述动作关联到某一个菜单项里面

fileMenu.addAction(exitAction)

以上这篇对pyqt5之menu和action的使用详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python批量图片处理简单示例

本文实例讲述了python批量图片处理。分享给大家供大家参考,具体如下: #!/usr/bin/python #coding:utf-8 import os from PIL imp...

Python面向对象实现一个对象调用另一个对象操作示例

本文实例讲述了Python面向对象实现一个对象调用另一个对象操作。分享给大家供大家参考,具体如下: 我先总结一下python中的类的特点: 1.类中所有的方法的参数中都必须加self,并...

解决python replace函数替换无效问题

python replace函数替换无效问题 str = "hello,china!" str.replace("hell","well") print(str) hello,C...

python的描述符(descriptor)、装饰器(property)造成的一个无限递归问题分享

分享一下刚遇到的一个小问题,我有一段类似于这样的python代码: 复制代码 代码如下: # coding: utf-8 class A(object):   &nb...

python django model联合主键的例子

今天,在家试试django的model的设置,如何设置的联合主键,我经过查资料和实践,把结果记录如下: 例如: class user(Model): id=AutoField(pr...