有可能有带有二进制输入的纺丝箱吗。让我们说"10010“。向上和向下滚动二进制增量/递减。
发布于 2020-01-16 20:16:59
要使用二进制系统,必须将displayIntegerBase属性设置为2:
import sys
from PyQt5 import QtWidgets
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QSpinBox()
w.setValue(0b10010)
w.setDisplayIntegerBase(2)
w.show()
sys.exit(app.exec_())更新:
如果希望设置最小宽度(在本例中为5),则必须重写textFromValue()方法:
import sys
from PyQt5 import QtWidgets
class SpinBox(QtWidgets.QSpinBox):
def textFromValue(self, value):
return "{:05b}".format(value)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
w = SpinBox()
w.setMaximum(0b11111)
w.setValue(0b00000)
w.setDisplayIntegerBase(2)
w.show()
sys.exit(app.exec_())

https://stackoverflow.com/questions/59776935
复制相似问题