Re: QSpinbox Button Access
Quote:
I would like to catch the mousepress event of a spin box in order to be able to reconfigure the box settings before the value actually changes.
You can either subclass, or use an event filter.
Re: QSpinbox Button Access
Well, that doesn't solve my problem. Of course I can subclass and catch the event but I don't know which button was pressed. I don't see a way to find out whether up or down button was pressed!
m.
Re: QSpinbox Button Access
Re: QSpinbox Button Access
:-) I guess there's still some misunderstanding ... I need access to the up/down buttons of the spinbox. I have subclassed QSpinbox already but I have no way to identify whether up or down was pressed when in mousepressevent !
Re: QSpinbox Button Access
you can tell by the value.
If the incoming value is larger than it was the up arrow, otherwise the down.
Re: QSpinbox Button Access
Actually I can't as at the time I enter mousepressevent the current value has not changed yet. Step up or down is triggered in exactely this function.
I'm looking for a way to identify the pressed button ...
Added after 28 minutes:
Ok, finally found out how it work's !! (similar to QSpinBox but quite tricky to find out)
Subclass QSpinBox and overwrite QSpinBox::mousePressEvent.
Get the SubClass rectangle of the corresponding SpinBox arrow of the complex control first, then check whether your mouse pointer position is inside the rectangle, that's it.
See the code snippet:
QStyleOptionSpinBox opt;
this->initStyleOption(&opt);
QRect rect = this->style()->subControlRect(QStyle::CC_SpinBox,&opt,QStyle::SC _SpinBoxUp);
if(rect.contains(event->pos()))
qDebug() << "UP";
else
qDebug() << "DOWN";
Cheers
M.
Re: QSpinbox Button Access