Use user-specifying QSlider step



  • Hi, all:

    Another naive question.

    I'm using Ubuntu 12.10+Qt Creator 2.5.2 Based on Qt 4.8.2 (32 bit)
    I'm trying to design a slider with interval 2, starting from 1 and ending in 9.
    Namely, I hope the possible values obtained while I'm dragging the slider are:
    1, 3, 5, 7, 9(all odd numbers)

    And, my code in the produced ui file is copied as follows:
    @horizontalSlider_aperturesize = new QSlider(edgedetectiondialog_laplacian);
    horizontalSlider_aperturesize->setObjectName(QString::fromUtf8("horizontalSlider_aperturesize"));
    horizontalSlider_aperturesize->setGeometry(QRect(150, 20, 180, 30));
    horizontalSlider_aperturesize->setMinimum(1);
    horizontalSlider_aperturesize->setMaximum(9);
    horizontalSlider_aperturesize->setSingleStep(2);
    horizontalSlider_aperturesize->setPageStep(3);
    horizontalSlider_aperturesize->setValue(3);
    horizontalSlider_aperturesize->setOrientation(Qt::Horizontal);
    horizontalSlider_aperturesize->setTickPosition(QSlider::TicksBelow);
    horizontalSlider_aperturesize->setTickInterval(2);
    @

    I really can't see anything wrong, but my later-on code went wrong because I got 4 from the slider reading (obviously, this is an even number, which is out of my expectation.)

    Any suggestions on how to avoid such mistakes?

    Thank you very much.

    Best Regards
    Pei



  • Hi,

    I think you should create your Slider class inherithed from QSlider and reimplement setValue() slot to force values only to odd ones.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.