python - 如何在 PyQt5 中反转旋转框选择?

标签 python pyqt5 qspinbox

我在 PyQt5 中有一个旋转框,如下所示。我怎样才能逆转选择?即,如果我单击向下箭头,值就会上升,反之亦然。

spinbox

最佳答案

一个可能的解决方案是覆盖 stepBy()stepEnabled()方法:

import sys
from PyQt5 import QtWidgets


class ReverseSpinBox(QtWidgets.QSpinBox):
    def stepEnabled(self):
        if self.wrapping() or self.isReadOnly():
            return super().stepEnabled()
        ret = QtWidgets.QAbstractSpinBox.StepNone
        if self.value() > self.minimum():
            ret |= QtWidgets.QAbstractSpinBox.StepUpEnabled
        if self.value() < self.maximum():
            ret |= QtWidgets.QAbstractSpinBox.StepDownEnabled
        return ret

    def stepBy(self, steps):
        return super().stepBy(-steps)


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    w = ReverseSpinBox()
    w.resize(320, 20)
    w.show()
    sys.exit(app.exec_())

关于python - 如何在 PyQt5 中反转旋转框选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62821244/

相关文章:

python - 终止当前的SSH连接

python - 'QPixmap' 没有属性 'grabWindow'

python - 为什么其他窗口(GUI)在Python中运行时其他窗口(GUI)没有打开?

c++ - QSpinBox 输入 NaN 作为有效值

python - PySide 获取 QSpinBox 中箭头按钮的宽度

python - 如何在python中使用向量化 'solve_ivp'实现='True'

python - 如何从 urllib.request 获取 cookie?

python - PyParsing 的 searchString 与 StringStart() 和 StringEnd()

python - QComboBox 的 PyQt 右键单击​​菜单

qt - 在 QSpinBox 中设置特定值