2進数のQSpinbox

クリスト

バイナリ入力のスピンボックスを持つことは可能ですか?「10010」としましょう。上下にスクロールすると、バイナリのインクリメント/デクリメントが行われます。

eyllanesc

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_())

ここに画像の説明を入力してください

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事