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设计】。

相关文章

numpy 对矩阵中Nan的处理:采用平均值的方法

尽管我们可以将所有的NaN替换成0,但是由于并不知道这些值的意义,所以这样做是个下策。如果它们是开氏温度,那么将它们置成0这种处理策略就太差劲了。 下面我们用平均值来代替缺失值,平均值根...

Python3 实现随机生成一组不重复数并按行写入文件

笔主在做一个项目要生成一组随机有序的整型数字,并按行输出到文本文件使用,恰好开始学习Python3,遂决定直接使用Python3解决 思路:与随机数相关的函数都要使用到random这个系...

用Pycharm实现鼠标滚轮控制字体大小的方法

用Pycharm实现鼠标滚轮控制字体大小的方法

一、pycharm字体放大的设置 File —> setting —> Keymap —>在搜寻框中输入:increase —> Increase Font Si...

解决python文件字符串转列表时遇到空行的问题

文件内容如下: Alex 100000 Rain 80000 Egon 50000 Yuan 30000 #此处有一个空行! 现在看如何处理并转成列表! sal...

python获得一个月有多少天的方法

本文实例讲述了python获得一个月有多少天的方法。分享给大家供大家参考。具体分析如下: 在python的datetime模块中没有一个月有多少天的方法,但是可以使用calendar模块...