当前位置:网站首页>pyQt 中 QMenu 响应
pyQt 中 QMenu 响应
2022-06-24 06:57:00 【Qredsun】
需求场景:
在qt界面中,需要给菜单添加响应动作。
实现:
查看了QMenu 对象源码,没有找到类似QPushButton.clicked()的信号函数。只发现了QMenu.triggered() 函数,已经常用的QMenu.addAction()。就是说,只能通过triggered触发出菜单列表,在菜单列表中添加QAction(),使用QAction()关联对应的槽函数,实现操作响应。
具体实现:
- qt界面中的控件关联关系:
# UI 关联
menuBar = QtWidgets.QMenuBar() # 菜单栏
menuBar.setGeometry(QtCore.QRect(0, 0, 1245, 23))
menuBar.setObjectName("menuBar")
menu = QtWidgets.QMenu() # 菜单按钮
menu.setObjectName("menu")
menu_check = QtWidgets.QMenu(menuBar)
menu_check.setObjectName("menu_check")
actionSavePicture = QtWidgets.QAction() # 动作响应,修改存放路径
actionSavePicture.setObjectName("actionSavePicture")
menu.addAction(actionSavePicture) # 菜单按钮添加动作
- 后端响应代码中的信号槽关联
actionSavePicture.triggered.connect(changeImgSavePath)
def changeImgSavePath():
# 获取目录路径
save_path = QFileDialog.getExistingDirectory(None, caption='选择截图存放目录')
if save_path:
img_save_path = save_path
cam_conf = CameraConfig()
cam_conf.img_save_path = save_path
cam_conf._update_cfg_file()
QMessageBox.about(None, '提示', f'截图存放目录变更为:{
save_path}')
else:
QMessageBox.about(None, '提示', '截图存放目录未变更')
边栏推荐
- Swift extension networkutil (network monitoring) (source code)
- Atguigu---15- built in instruction
- OC Extension 检测手机是否安装某个App(源码)
- Introduction to software engineering - Chapter 2 - feasibility study
- 2021-03-04 COMP9021第六节课笔记
- [ACNOI2022]做过也不会
- Teach you how to use the reflect package to parse the structure of go - step 1: parameter type check
- Optimization and practice of Tencent cloud EMR for cloud native containerization based on yarn
- Synchronous FIFO
- 不止于观测|阿里云可观测套件正式发布
猜你喜欢

About the iframe anchor, the anchor is offset up and down, and the anchor has page display problems Srcdoc problem of iframe

SCM stm32f103rb, BLDC DC motor controller design, schematic diagram, source code and circuit scheme

The monthly salary of two years after graduation is 36K. It's not difficult to say

Use of swift basic closure /block (source code)

JDBC 在性能测试中的应用

How to use the virtual clock of FPGA?
![[008] filter the table data row by row, jump out of the for cycle and skip this cycle VBA](/img/a0/f03b8d9c8f5e53078c38cce11f8ad3.png)
[008] filter the table data row by row, jump out of the for cycle and skip this cycle VBA

Svn actual measurement common operation record operation

蓝桥杯_N 皇后问题

Simple summary of lighting usage
随机推荐
Signature analysis of app x-zse-96 in a Q & a community
[nilm] non intrusive load decomposition module nilmtk installation tutorial
How to use the virtual clock of FPGA?
Review of postgraduate English final exam
Saccadenet: use corner features to fine tune the two stage prediction frame | CVPR 2020
论文笔记: 多标签学习 DM2L
Qopengl display point cloud file
Ad-gcl:advantageous graph augmentation to improve graph contractual learning
2021-03-09 COMP9021第七节课笔记
C# Lambda
Vulnhub target: boredhackerblog: social network
Graphmae ---- quick reading of papers
Getting started with crawler to giving up 06: crawler play Fund (with code)
2021-03-16 COMP9021第九节课笔记
Optimization and practice of Tencent cloud EMR for cloud native containerization based on yarn
2022茶艺师(中级)上岗证题库及在线模拟考试
transformers PreTrainedTokenizer类
Transformers pretrainedtokenizer class
贷款五级分类
根据网络上的视频的m3u8文件通过ffmpeg进行合成视频