首页 > 编程 > Python > 正文

pyqt5 实现工具栏文字图片同时显示

2019-11-25 12:45:47
字体:
来源:转载
供稿:网友

如下所示:

import sysfrom PyQt5.QtWidgets import QMainWindow, QTextEdit, QAction, QApplicationfrom PyQt5.QtGui import QIconfrom PyQt5.QtCore import Qtclass Example(QMainWindow):  def __init__(self):    super().__init__()    self.initUI()  def initUI(self):    textEdit = QTextEdit()    self.setCentralWidget(textEdit)    exitAction = QAction(QIcon('images/exit.png'), 'Exit',self)    exitAction.setShortcut('Ctrl+Q')    exitAction.setStatusTip('Exit application')    exitAction.triggered.connect(self.close)    self.statusBar()    menubar = self.menuBar()    fileMenu = menubar.addMenu('&File')    fileMenu.addAction(exitAction)    toolbar = self.addToolBar('Exit')    # toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) # 文字图片垂直排列    toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) # 文字图片水平排列    toolbar.addAction(exitAction)    self.setGeometry(300, 300, 350, 250)    self.setWindowTitle('Main window')    self.show()if __name__ == '__main__':  app = QApplication(sys.argv)  ex = Example()  sys.exit(app.exec_())

以上这篇pyqt5 实现工具栏文字图片同时显示就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持武林网。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表