QIcon隐藏的动作可检查属性

时间:2018-01-03 15:47:02

标签: python qt pyqt pyqt5

class window21(QtWidgets.QMainWindow):
    def __init__(self):
        super(window21,self).__init__()
        self.newAction=QtWidgets.QAction(QtGui.QIcon(":/im/new.png"),"&New",self,checkable=True)
        self.openAction=QtWidgets.QAction("&Open",self,checkable=True)
        self.printAction=QtWidgets.QAction("&Print",self,checkable=True)
#        self.quitAction=QtWidgets.QAction(QtGui.QIcon(":/im/quit.png"),"&Quit",self,checkable=True)
#        self.saveAction=QtWidgets.QAction(QtGui.QIcon(":/im/save.png"),"&Save",self,checkable=True)
        self.quitAction=QtWidgets.QAction("&Quit",self,checkable=True)
        self.saveAction=QtWidgets.QAction("&Save",self,checkable=True)

        self.groupMenu=QtWidgets.QMenu("nested menu",self)
        self.groupAction=QtWidgets.QActionGroup(self)



        myMenu=self.menuBar()
        file=myMenu.addMenu("&File")
        file.addAction(self.newAction)
        file.addAction(self.openAction)
        file.addAction(self.printAction)
#        file.addAction(actions[0])

        self.groupAction.addAction(self.quitAction)
        self.groupAction.addAction(self.saveAction)


        self.groupAction.setExclusive(True)

        for j in self.groupAction.actions():
            j.setCheckable(True)
            self.groupMenu.addAction(j)

        try:
            file.addMenu(self.groupMenu)
        except Exception as E:
            print(E)

        self.show()

app=QtWidgets.QApplication([])
ex=window21()
sys.exit(app.exec_())

我正在创建一个简单的菜单并了解可检查的属性。最初我的所有操作都附加了QIcon。所以当我为他们设置checkable属性时,我无法看到结果。因为我无法看到它真的起作用了。经过一些实验,我发现QIcon隐藏了支票,因此无法看到。所以我在考虑是否可以显示Icon以及右边的支票

0 个答案:

没有答案