对pyqt5之menu和action的使用详解

(编辑:jimmy 日期: 2025/7/6 浏览:2)

如下所示:

 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的使用详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。