pyqt5实现工具栏文字图片同时显示-创新互联

如下所示:

成都创新互联公司是网站建设专家,致力于互联网品牌建设与网络营销,专业领域包括网站建设、成都做网站、电商网站制作开发、成都微信小程序、微信营销、系统平台开发,与其他网站设计及系统开发公司不同,我们的整合解决方案结合了恒基网络品牌建设经验和互联网整合营销的理念,并将策略和执行紧密结合,且不断评估并优化我们的方案,为客户提供全方位的互联网品牌整合方案!
import sys
from PyQt5.QtWidgets import QMainWindow, QTextEdit, QAction, QApplication
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import Qt

class 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实现工具栏文字图片同时显示-创新互联
分享地址:http://myzitong.com/article/djihes.html