当前位置:   article > 正文

PyQt5 QToolButton运用_pyqt5 qtool怎么复用

pyqt5 qtool怎么复用
#!/user/bin/env python3
# -*- coding: utf-8 -*-
import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from imgOperation import *

ICON_WIDTH = 50
ICON_HEIGHT = 30
LEFTWIDGET_HEIGHT = 60
BUTTON_HEIGHT = 54
BUTTON_WIDTH = 54

'''切换栏'''


class LeftWidget(QWidget):
    def __init__(self, parent=None):
        super(LeftWidget, self).__init__(parent)

        # self.setWindowFlags(Qt.FramelessWindowHint)
        # 垂直布局按照从上到下的顺序进行添加按钮部件。

        mainLayout = QVBoxLayout()
        self.m_pButtonHome = QToolButton(self)
        self.m_pButtonHosiery = QToolButton(self)

        self.m_pButtonHome.setText('首页')
        self.m_pButtonHome.setIcon(QIcon('./images/home-left.png'))
        # 图片下显示首页
        self.m_pButtonHome.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        self.m_pButtonHome.setIconSize(QSize(ICON_WIDTH, ICON_HEIGHT))
        self.m_pButtonHome.setFixedWidth(BUTTON_WIDTH)
        self.m_pButtonHome.setFixedHeight(BUTTON_HEIGHT)

        self.m_pButtonHosiery.setText('历史')
        self.m_pButtonHosiery.setIcon(QIcon('./images/hosiery.png'))
        # 图片下显示历史
        self.m_pButtonHosiery.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        self.m_pButtonHosiery.setIconSize(QSize(ICON_WIDTH, ICON_HEIGHT))
        self.m_pButtonHosiery.setFixedWidth(BUTTON_WIDTH)
        self.m_pButtonHosiery.setFixedHeight(BUTTON_HEIGHT)

        mainLayout.addWidget(self.m_pButtonHome)
        mainLayout.addWidget(self.m_pButtonHosiery)

        # 事件
        self.m_pButtonHome.clicked.connect(self.onHomeClick)
        self.m_pButtonHosiery.clicked.connect(self.onHosieryClick)

        # 设置主窗口
        self.setLayout(mainLayout)

        # 设置间距
        mainLayout.setSpacing(0)

        # 主窗口居中
        self.resize(150, 200)

    def onHomeClick(self):
        print('主界面点击')

    def onHosieryClick(self):
        print('历史记录点击')


if __name__ == "__main__":
    app = QApplication(sys.argv)
    w = LeftWidget()
    w.show()
    sys.exit(app.exec_())

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/961304
推荐阅读
相关标签
  

闽ICP备14008679号