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

yipeiwu_com5年前Python基础

如下所示:

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 实现工具栏文字图片同时显示就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python 寻找优化使成本函数最小的最优解的方法

今天来学习变量优化问题。寻找使成本函数最小的题解。适用于题解相互独立的情况,设计随机优化算法、爬山法、模拟退火算法、遗传算法。 优化问题的的精髓是:1、将题解转化为数字序列化,可以写出题...

Python re模块介绍

Python中转义字符 正则表达式使用反斜杠” \ “来代表特殊形式或用作转义字符,这里跟Python的语法冲突,因此,Python用” \\\\ “表示正则表达式中的” \ “,因为正...

Python使用遗传算法解决最大流问题

Python使用遗传算法解决最大流问题

本文为大家分享了Python遗传算法解决最大流问题,供大家参考,具体内容如下 Generate_matrix def Generate_matrix(x,y): import...

在Python中增加和插入元素的示例

在Python中append 用来向 list 的末尾追加单个元素,如果增加的元素是一个list,那么这个list将作为一个整体进行追加。 例如: Python代码 li=['a',...

Python中的字符串查找操作方法总结

基本的字符串位置查找方法 Python 查找字符串使用 变量.find("要查找的内容"[,开始位置,结束位置]),开始位置和结束位置,表示要查找的范围,为空则表示查找所有。查找到后会返...