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_())
相关推荐
ITxiaobaibai 2020-07-04
alanlonglong 2020-06-14
PeterHuang0 2020-05-26
大地飞鸿 2020-01-06
飞翔的鱼 2019-11-16
yyHaker 2019-10-21
yangzzguang 2019-10-21
chenzhx 2019-09-06
我心飞翔之家 2019-04-01
咸鱼的星空 2018-09-25
那年夏天 2019-06-30
js网页特效 2019-06-28
zgwyfz 2018-09-25
hotbillow 2013-12-04
有心就有方向 2013-11-07
hexiankun 2016-02-03
kwenLee 2011-06-09
mianqiang 2010-05-16