需求描述
当我们利用qtdesigner创建menu后,想在menu中添加checkbox复选框,结果qtdesigner并不支持该操作
解决方法
找到ui转py后的文件,添加对应代码即可。
from PyQt5.QtWidgets import QCheckBox
from PyQt5.QtWidgets import QWidgetAction
self.checkBox = QCheckBox('原生命令窗口')
action = QWidgetAction(self)
action.setDefaultWidget(self.checkBox)
self.checkBox1 = QCheckBox('开机启动')
action1 = QWidgetAction(self)
action1.setDefaultWidget(self.checkBox1)
self.menu_5.addAction(action)
self.menu_5.addAction(action1)
这样你就可以得到一个带有checkbox的menu内容。