QSpinBox: step regulator and a single text box
Case
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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 Learning " ) 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 ( the lambda Val: Print (type (Val), Val)) BTN = the QPushButton (Self) btn.setText ( " test button " ) btn.move ( 150, 150 ) btn.clicked.connect ( the lambda :. sb.lineEdit () the setText ( " 30 * 30 " )) # . Self Max Min () DEF setting and getting values (Self): # self.sb.setRange (0, 9) self.sb.setPrefix ( " stitch class " ) # self.sb.setValue (66) Print (self.sb.value ()) Print (self.sb.text ()) Print (self.sb.lineEdit ( ) .text ()) Pass DEF hexadecimal setting (self) shows: Print (self.sb.displayIntegerBase ()) self.sb.setDisplayIntegerBase ( 2 ) Print(self.sb.displayIntegerBase ()) DEF prefixes and suffixes (Self): # self.sb.setRange (1, 12) # self.sb.setSuffix ( "May") self.sb.setRange (0, 6 ) Self .sb.setPrefix ( " periphery " ) self.sb.setSpecialValueText ( " Sun " ) Pass DEF step size (Self): self.sb.setSingleStep ( . 3 ) DEF value cycle (Self): Print (self.sb. Wrapping ()) self.sb.setWrapping (True) Print (self.sb.wrapping ()) DEFMaximum Minimum (Self): # self.sb.setMaximum (180 [) # Print (self.sb.maximum ()) # self.sb.setMinimum (18 is) # Print (self.sb.minimum ()) Self. sb.setRange (18 is, 180 [ ) IF the __name__ == ' __main__ ' : Import SYS App = the QApplication (the sys.argv) window = the window () window.show () the sys.exit (app.exec_ ())