PDA

View Full Version : Activate QPushButton with QCursor



blizniak83
13th March 2012, 10:47
Hello everyone,

I would like to get some advice. I'm going to subclass QPushButton which will be controlled by a QCursor.
I want to use QCursor::setPos() to set the position of the cursor which will be responsible for activating a QPushButton.

The idea is to activate the button after hovering it for longer than 3-5 seconds. I want to use QCursor to control a cursor's position,
where x and y coordinates will come from a different widget and will be used to activate different buttons. The only way I can think
of is to create a button - animated widget something like a progress bar which after filling itself completely will be activated.

The concept will be very similar to the one used in MS Kinect games, where the buttons are activated using hands.

Any ideas and suggestions are more than welcome, maybe I'm missing something that could help me to implement
this kind of functionality. The biggest issue will be most probably with controlling a cursor's position within my window.

Thank you,
Chris

high_flyer
13th March 2012, 14:29
Since I don't know MS Knect games, its hard for me to follow on what you exactly are trying to achieve.
However:

The idea is to activate the button after hovering it for longer than 3-5 seconds.
For this you don't need a QCursor - you can just trap the buttons enter and leave events.

blizniak83
3rd April 2012, 20:19
Thanks for the reply. I think I didn't have a clear idea what I want to do at the time when I posted the question for the first time. Today I'll try to keep it simple.

I've got separate widget - QGLWidget. The GL window will be displayed on the separate screen.
On top of my GL widget or within that widget I will add something like a pushbutton or some simple graphics. I'm only interested in the position of that region within GL widget.

Then I want to use 2d position of my hand from the camera image to control the previously mentioned region. The way I want to do that is to call a desired function after 2d point will be within region of interest for longer than 3 seconds let say.

I've seen something similar where MS Kinect and Qt gestures were used.

I'm not sure if this makes more sense, but it is doable.

wysota
4th April 2012, 09:01
I think Daniel's answer still stands -- the button doesn't care about Kinect or anything else related to how the cursor position is set. You get enter and leave events for the button and in the enter event you can start a timer. If it fires before a corresponding leave event is received then it means the cursor was over the button for the specified amount of time and you can call click() on the button.