07.PyQt5菜单栏及右击栏的实现
import sys
from PyQt5
.Qt
import *
class App(QWidget
):
def __init__(self
):
super().__init__
()
self
.setWindowTitle
('menu')
self
.resize
(500,500)
self
.menu1
()
def menu1(self
):
file=QPushButton
('File',self
)
file.setFlat
(True)
file_menu
=QMenu
()
file_menu
.addAction
(QAction
('New',file_menu
))
file_menu
.addAction
(QAction
('Open', file_menu
))
rencent_file_menu
=QMenu
(file_menu
)
rencent_file_menu
.setTitle
('recent files')
rencent_file_menu
.addAction
(QAction
('123',rencent_file_menu
))
rencent_file_menu
.addAction
(QAction
('456', rencent_file_menu
))
file_menu
.addMenu
(rencent_file_menu
)
file_menu
.addAction
(QAction
('close',file_menu
))
file.setMenu
(file_menu
)
def contextMenuEvent(self
,a
):
print(a
.globalX
(),a
.globalY
())
menu
=QMenu
(self
)
menu
.addAction
(QAction
('export',menu
))
menu
.exec_
(a
.globalPos
())
if __name__
== '__main__':
app
=QApplication
(sys
.argv
)
window
=App
()
window
.show
()
sys
.exit
(app
.exec_
())
转载请注明原文地址:https://ipadbbs.8miu.com/read-2175.html