[Qt-interest] Scroll on a digit to change its value

Enrico Ros enrico.qt at email.it
Fri Oct 30 10:43:11 CET 2009


Hello Giacomo, 

On Friday 30 October 2009 08:30:50 Giacomo wrote:
> Hi to all.
> 
> Suppose I have a QDoubleSpinbox which normally displays
> a wide number of digits, for instance
> 
> 100.01125
> 
> To quickly change each digit, it could be useful to place the mouse over
> one of them an scroll with the wheel, increasing or decreasing the
> _single digit_ value. This means, on the number above, I place the mouse
> pointer over the "2" digit and I scroll the wheel up and down to change
> only that digit.
> 
> Can anyone suggest a way to do this? Might it be possible?

There is  no such behavior in the common spinbox, so you have to create a 
custom widget or 'enrich' an existing one.

So, you cold either:
 - create a new spinbox subclassing QAbstractSpinBox
 - look into the code of QDoubleSpinBox (qt/src/gui/qspinbox.{h, cpp}) and 
create a similar one
 - subclass QDoubleSpinbox

The third one sounds tricky and actually is, but it may be the fastest 
solution, even if really dependant from the style and contents. It could be 
like this:

class WheelableDoubleSpin : public QDoubleSpinBox {
    public:
        WheelableDoubleSpin(QWidget * parent = 0) : QDoubleSpinBox(parent) {}

        void wheelEvent(QWheelEvent * event) {
            // 1. find out which digit/decimal are we over: example for 8 
digits and 10 pixel wide right-arrows
            int digit = (event->x() - 10) / 8;

            // 2. increment/decrement that number (10^digit)
            qreal val = pow(10, digit);
            if (event->delta() < 0)
                val = -val;

            // 3. change value
            setValue(value() + val);
        }
};

I don't have tested this, it's here just to show the (hack) principle ;-)
Enrico
 
 
 --
 Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP autenticato? GRATIS solo con Email.it http://www.email.it/f
 
 Sponsor:
 Prova il servizio di Email Marketing di Email.it, incrementi la visibilita' della tua azienda e trovi nuovi clienti.
* Liste a partire da 10.000 contatti per soli 250 Euro
 Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=8351&d=30-10



More information about the Qt-interest-old mailing list