• pyqt5学习之QSpinBox


    QSpinBox:步长调节器和一个单行文本框

    案例

    from PyQt5.Qt import *
    
    class SB(QSpinBox):
        def textFromValue(self, p_int):
            print("xx2", p_int)
            # 1 * 1
            return str(p_int) + "*" + str(p_int)
    
        def valueFromText(self, p_str):
            print("xxxx", p_str)
    
    class Window(QWidget):
        def __init__(self):
            super().__init__()
            self.setWindowTitle("QSpinBox的学习")
            self.resize(500, 500)
            self.setup_ui()
    
        def setup_ui(self):
            sb = SB(self)
            self.sb = sb
            sb.resize(100, 25)
            sb.move(100, 100)
            sb.valueChanged[str].connect(lambda val: print(type(val), val))
    
            btn = QPushButton(self)
            btn.setText("测试按钮")
            btn.move(150, 150)
            btn.clicked.connect(lambda :sb.lineEdit().setText("30*30"))
    
            # self.最大值最小值()
    
        def 设置以及获取数值(self):
            # self.sb.setRange(0, 9)
            self.sb.setPrefix("撩课")
            # self.sb.setValue(66)
            print(self.sb.value())
            print(self.sb.text())
            print(self.sb.lineEdit().text())
            pass
    
        def 显示的进制设置(self):
            print(self.sb.displayIntegerBase())
            self.sb.setDisplayIntegerBase(2)
            print(self.sb.displayIntegerBase())
    
        def 前缀和后缀(self):
            # self.sb.setRange(1, 12)
            # self.sb.setSuffix("月")
            self.sb.setRange(0, 6)
            self.sb.setPrefix("")
            self.sb.setSpecialValueText("周日")
            pass
    
        def 步长设置(self):
            self.sb.setSingleStep(3)
    
        def 数值循环(self):
            print(self.sb.wrapping())
            self.sb.setWrapping(True)
            print(self.sb.wrapping())
    
        def 最大值最小值(self):
            # self.sb.setMaximum(180)
            # print(self.sb.maximum())
            # self.sb.setMinimum(18)
            # print(self.sb.minimum())
            self.sb.setRange(18, 180)
    
    if __name__ == '__main__':
        import sys
        app = QApplication(sys.argv)
    
        window = Window()
        window.show()
    
    
        sys.exit(app.exec_())
    View Code

  • 相关阅读:
    你可能不知道的 transition 技巧与细节
    CSS奇思妙想 -- 使用 CSS 创造艺术
    生僻标签 fieldset 与 legend 的妙用
    CSS 奇思妙想边框动画
    (转)linux命令-- pstack命令(跟踪进程栈)
    (转)PostgreSQL 数据库错误代码解释
    postgresql灾备切换
    (转)postgresql配置参数和概念解释
    (转)PostgreSQL跨库操作Oracle利器-Oracle_fdw
    (转)PG运维常用知识点小结
  • 原文地址:https://www.cnblogs.com/mosewumo/p/12540521.html
Copyright © 2020-2023  润新知