【问题标题】:Custom qt spinbox for auto rotating values after reaching the limits达到限制后自动旋转值的自定义 qt spinbox
【发布时间】:2019-08-25 07:38:27
【问题描述】:

我希望我的 Qt Spin-box 在用户到达值范围的两端时旋转值。

例如让我的范围是 0 到 10,增量为 2。当值已经为 10 时单击旋转框的增量按钮后,通常什么也没有发生。但我希望它将值旋转回第一个值为 0 的值。

我必须重写哪个成员函数来捕获用户尝试更改 QSpinBox 类中的值的事件?

class MyCustomSpinBox : public QSpinBox
{
    // override this function to get the effect of rotating
    void override_func()
    {
    // code to rotate the value 
    }
};

或者,是否已经存在它的某些属性,以便我可以在 qt-creator 中设置(可能)以获得相同的旋转值效果?

谢谢。

【问题讨论】:

  • 没错,在两端,显然可以永无止境地继续下去。

标签: c++ qt qt5 qspinbox


【解决方案1】:

你可以只启用 wrapping 。

例如。

QSpinBox *spinBox = new QSpinBox(this);
spinBox->setRange(0, 100);
spinBox->setWrapping(true);
spinBox->setValue(100);
spinBox->stepBy(1);
// value is 0

【讨论】:

    猜你喜欢
    • 2014-06-22
    • 1970-01-01
    • 2011-03-08
    • 2011-01-29
    • 1970-01-01
    • 2018-08-24
    • 1970-01-01
    • 1970-01-01
    • 2015-09-20
    相关资源
    最近更新 更多