【问题标题】:How to reverse spinbox selection in PyQt5?如何在 PyQt5 中反转旋转框选择?
【发布时间】:2020-07-09 18:20:18
【问题描述】:

我在 PyQt5 中有一个旋转框,如下所示。如何使选择反转?即,如果我单击向下箭头,则值会上升,反之亦然。

【问题讨论】:

    标签: python pyqt5 qspinbox


    【解决方案1】:

    一种可能的解决方案是覆盖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_())
    

    【讨论】:

      猜你喜欢
      • 2021-07-06
      • 2011-12-03
      • 2021-10-20
      • 1970-01-01
      • 2021-04-02
      • 2020-10-26
      • 2022-01-21
      • 2023-03-02
      • 1970-01-01
      相关资源
      最近更新 更多