QSpinBox学習

QSpinBox学習

from PyQt5.Qt import *
import sys

class SB(QSpinBox):
    def textFromValue(self, p_int):
        print(p_int)
        return "itlike"
class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle('QSpinBox的学习')
        self.resize(500, 500)
        self.setup_ui()

    def setup_ui(self):
        # sb=QSpinBox(self)
        sb=SB(self)
        self.sb=sb
        sb.resize(100,25)
        sb.move(100,100)

        #信号
        sb.valueChanged.connect(lambda :print(type(sb.value())))

        btn=QPushButton(self)
        btn.setText("测试按钮")
        btn.move(150,150)
        btn.clicked.connect(lambda :self.设置以及获取数值())


        # btn.pressed.connect(最大值最小值)
    def 设置以及获取数值(self):
        # self.sb.setRange(0,9)
        self.sb.setPrefix("撩课")
        # self.sb.setValue(66)
        #只获得数值
        print(self.sb.value())
        #都获得
        print(self.sb.text())
        pass
    def 进制设置(self):
        print(self.sb.displayIntegerBase())
        self.sb.setRange(0,101)
        self.sb.setDisplayIntegerBase(2)
        print(self.sb.displayIntegerBase())

    def 前缀和后缀(self):
        '''
        4
        :return:
        '''
        self.sb.setRange(0,6)
        self.sb.setPrefix("周")
        self.sb.setSpecialValueText("周日")
        # #前缀
        # self.sb.setPrefix("周")
        # print(self.sb.prefix())
        # #后缀
        # self.sb.setSuffix("月")
        # print(self.sb.suffix())
    def 设置步长(self):
        '''
        3
        :return:
        '''
        print(self.sb.singleStep())
        self.sb.setSingleStep(5)

    def 数值循环(self):

        '''
        2
        :return:
        '''
        print(self.sb.setWrapping())
        self.sb.setWrapping(True)
        print(self.sb.setWrapping())
    def 最大值最小值(self):
        '''
        1
        :return:
        '''
        # self.sb.setMaximum(80)
        # print(self.sb.maximum())
        # self.sb.setMinimum(18)
        # print(self.sb.minimum())
        self.sb.setRange(18,80)



if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())



公開された41元の記事 ウォンの賞賛0 ビュー788

おすすめ

転載: blog.csdn.net/qestion_yz_10086/article/details/104535452