PDA

View Full Version : Can I get button Event on QSpinBox



sosanjay
7th January 2010, 07:44
Hi All,

I want to use button event instead of value changed Signal.
Is there any way that I get button event Signal of QSpinBox.

connect(ui->inputSpinBox, SIGNAL(valueChanged (int)), this, SLOT(SelectDisplay()));

Can anyone tell me How to Implement Mouse Click event if there is no button event.

high_flyer
7th January 2010, 11:00
You can install and event Filter on your spin box and trap any event you want there.
http://doc.trolltech.com/4.5/qobject.html#installEventFilter

sosanjay
7th January 2010, 11:09
But In SpinBox there are two Buttons One for Increment and another is for decrement. So How can I distinguish between them.

I want to write different function on Increment and decrement.

Plz help me out for this problem.

high_flyer
8th January 2010, 10:09
Well, one way would be to look in the QSpinBox code.

The other one, you could see if the current value is higher or lower then the last value, thus knowing which button was clicked.

BTW - why is it that you don't use the valueChanged() signal?
This is quite odd, and points probably to either potentially bad design.
If you explain what it is you are trying to solve, we might help you with a better solution.

glennh
25th September 2010, 04:29
I find myself wanting to do the same thing. Here's why:
I want to make an edit field that has multiple sub-fields. A good example of something like what I'm trying to do is QDateEdit. Unfortunately, QDateEdit is much more complicated than I need. (I only need to do numeric entry separated by formatters, like 00-00-00-00.00) It also inherits from private interfaces, meaning it does things I can't. For my purposes, using the inputMask feature of QLineEdit seems like it would make the most sense. However, if I do that, then I lose the up-down arrows from QSpinBox. So, what it seems like would work is if I could connect the up-down arrows from a QSpinBox to my QLineEdit subclass... But, that doesn't seem to work either as this thread points out.
In short, inheriting from either QSpinBox or QLineEdit leaves me wishing I had some functionality from the other class. Its a bit of a pickle. Any suggestions?

hashb
25th September 2010, 09:27
maybe you need to create a customer widget for it