python PyQt用动作填充工具栏

Python (157) 2023-04-29 12:45:56

1、在工具栏中添加选项或按钮,需要调用.addAction()。

2、调用.addAction()作为参数,这将允许在菜单和工具栏之间分享操作。

当你创建工具栏时,你通常会面临决定添加哪些选项的问题。通常,你只想在工具栏中添加最常用的操作。

实例

classWindow(QMainWindow):
#Snip...
def_createActions(self):
#Fileactions
self.newAction=QAction(self)
self.newAction.setText("&New")
self.newAction.setIcon(QIcon(":file-new.svg"))
self.openAction=QAction(QIcon(":file-open.svg"),"&Open...",self)
self.saveAction=QAction(QIcon(":file-save.svg"),"&Save",self)
self.exitAction=QAction("&Exit",self)
#Editactions
self.copyAction=QAction(QIcon(":edit-copy.svg"),"&Copy",self)
self.pasteAction=QAction(QIcon(":edit-paste.svg"),"&Paste",self)
self.cutAction=QAction(QIcon(":edit-cut.svg"),"C&ut",self)
#Snip...

以上就是python PyQt用动作填充工具栏的方法,希望对大家有所帮助。

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

THE END

发表回复