日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

PyQt5-菜单栏工具栏状态栏的使用(QMenuBar、QToolBar、QStatusBar)

發布時間:2024/4/17 c/c++ 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PyQt5-菜单栏工具栏状态栏的使用(QMenuBar、QToolBar、QStatusBar) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、QMenuBar

窗體標題下方QMenuBar作為窗體菜單欄;QMenu對象提供了一個可以添加菜單欄的控件,也可以用于創建上下文菜單和彈出菜單選項;

每個QMenu對象都可以包含一個或者多個QAction對象或者級聯的QMenu對象;

createPopupMenu()方法用于彈出一個菜單;

menuBar()方法用于返回主窗口的QMenuBar對象;

addMenu()方法可以將菜單添加到菜單欄;

addAction() 方法可以在菜單中進行添加某些操作;

常用方法:

例如:

1 #QMenuBar/QMenu/QAction的使用(菜單欄) 2 from PyQt5.QtWidgets import QMenuBar,QMenu,QAction,QLineEdit,QStyle,QFormLayout, QVBoxLayout,QWidget,QApplication ,QHBoxLayout, QPushButton,QMainWindow,QGridLayout,QLabel 3 from PyQt5.QtCore import QDir 4 from PyQt5.QtGui import QIcon,QPixmap,QFont 5 from PyQt5.QtCore import QDate 6 7 import sys 8 9 class WindowClass(QMainWindow): 10 11 def __init__(self,parent=None): 12 13 super(WindowClass, self).__init__(parent) 14 self.layout=QHBoxLayout() 15 self.menubar=self.menuBar()#獲取窗體的菜單欄 16 17 self.file=self.menubar.addMenu("系統菜單") 18 self.file.addAction("New File") 19 20 self.save=QAction("Save",self) 21 self.save.setShortcut("Ctrl+S")#設置快捷鍵 22 self.file.addAction(self.save) 23 24 self.edit=self.file.addMenu("Edit") 25 self.edit.addAction("copy")#Edit下這是copy子項 26 self.edit.addAction("paste")#Edit下設置paste子項 27 28 self.quit=QAction("Quit",self)#注意如果改為:self.file.addMenu("Quit") 則表示該菜單下必須柚子菜單項;會有>箭頭 29 self.file.addAction(self.quit) 30 self.file.triggered[QAction].connect(self.processtrigger) 31 self.setLayout(self.layout) 32 self.setWindowTitle("Menu Demo") 33 34 def processtrigger(self,qaction): 35 print(qaction.text()+" is triggered!") 36 37 if __name__=="__main__": 38 app=QApplication(sys.argv) 39 win=WindowClass() 40 win.show() 41 sys.exit(app.exec_())

?

?

?

二、QToolBar工具欄

該控件是由文本按鈕、圖標或者其他小控件按鈕組成的可移動面板,通常位于菜單欄下方,作為工具欄使用;

每次單擊工具欄中的按鈕,此時都會觸發actionTriggered信號。這個信號將關聯QAction對象的引用發送到鏈接的槽函數上;

常用方法如下:

例如:結合上面menubar:

1 #QToolBar(工具欄) 2 from PyQt5.QtWidgets import QToolBar, QMenuBar,QMenu,QAction,QLineEdit,QStyle,QFormLayout, QVBoxLayout,QWidget,QApplication ,QHBoxLayout, QPushButton,QMainWindow,QGridLayout,QLabel 3 from PyQt5.QtGui import QIcon,QPixmap 4 5 6 import sys 7 8 class WindowClass(QMainWindow): 9 10 def __init__(self,parent=None): 11 super(WindowClass, self).__init__(parent) 12 self.layout=QVBoxLayout() 13 self.resize(200,300) 14 #菜單欄 15 menuBar=self.menuBar() 16 menu=menuBar.addMenu("File") 17 action=QAction(QIcon("./image/save.ico"),"New Project", self) 18 menu.addAction(action) 19 20 menu2=menu.addMenu("Add to ...") 21 menu2.addAction(QAction("workspace edit...",self)) 22 23 24 #工具欄 25 tool=self.addToolBar("File") 26 #edit=QAction(QIcon("./image/save.ico"),"刷新",self) 27 edit=QAction(QIcon("./image/save.ico"),"save",self) 28 tool.addAction(edit) 29 30 wifi=QAction(QIcon(QPixmap("./image/wifi.png")),"wifi",self) 31 tool.addAction(wifi) 32 tool.actionTriggered[QAction].connect(self.toolBtnPressed) 33 34 def toolBtnPressed(self,qaction): 35 print("pressed too btn is",qaction.text()) 36 if __name__=="__main__": 37 app=QApplication(sys.argv) 38 win=WindowClass() 39 win.show() 40 sys.exit(app.exec_())

?

?

?

三、狀態欄:QStatusBar

通過主窗口QMainWindow的setStatusBar()函數設置狀態欄信息;

例如:

self.statusBar=QstatusBar()

self.setStatusBar(self.statusBar)

常用方法:

例如:修改上面實例,添加如下程序,這是狀態欄信息;(點擊工具欄按鈕觸發槽函數執行,完成對狀態欄信息修改)

?

轉載于:https://www.cnblogs.com/ygzhaof/p/10070523.html

總結

以上是生活随笔為你收集整理的PyQt5-菜单栏工具栏状态栏的使用(QMenuBar、QToolBar、QStatusBar)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。