PDA

View Full Version : Flickable and mouse signal propagation



clousque
21st August 2014, 09:37
Hi,

In a Qml file, I have a Flickable area containing a custom QPushButton (registered thanks to qmlRegisterType()).

When I click on the button (without releasing the mouse button), the QPushButton changes its decoration as if it would be pressed, but if I move the mouse (mouse button still pressed), this initiates the flick movement. The release of the mouse button is then not transmitted to QPushButton so the QPushButton still has its almost pressed decoration.

The pressed event seems to be unsderstood by QPushButton and Flickable area, but once the flik move has started, the released event is get by the Flickable area only.

How can I get the release event for the QPushButton.

Thanks for your help.

wysota
21st August 2014, 10:33
Try putting an Item inbetween the push button and the flickable. If it doesn't work, try putting a MouseArea instead, setting its preventStealing property to true.

clousque
22nd August 2014, 09:23
Unfortunately none of your suggestions work for me.

There are already many Item elements between the Flickable and my QPushButton. What did you intend with this suggestion, I can't get the point ? Does the Item element have any interaction with mouse event that would be propagated to the QPushButton ?

The second is not working.

I finally get a workaround. I used the answer of this thread: http://qt-project.org/forums/viewthread/30007/
When my button is pressed, I send a signal to the Flickable to set its interactive attribute to false, this allows the button to get the release event. And in the onReleased() of my button, I send another signal to the Flickable to set its interactive attribute to true.

Thanks for your time

wysota
22nd August 2014, 09:45
What did you intend with this suggestion, I can't get the point ?
Flickable sets an event filter on its children. I was hoping that putting an additional item to separate Flickable and the other item events would not be stolen from that other item through that filter. The problem is probably that the pushbutton does not handle mouse move events and Flickable kicks in then grabbing all future events.

The second is not working.


I finally get a workaround. I used the answer of this thread: http://qt-project.org/forums/viewthread/30007/
When my button is pressed, I send a signal to the Flickable to set its interactive attribute to false, this allows the button to get the release event. And in the onReleased() of my button, I send another signal to the Flickable to set its interactive attribute to true.

That's very... crude :) And breaks a number of functionalities (e.g. scrolling the flickable with mouse wheel). I'd try either subclassing QGraphicsProxyWidget or QPushButton and in there prevent Flickable for gettng its hands on the widget's events.

clousque
22nd August 2014, 10:17
That's very... crude And breaks a number of functionalities (e.g. scrolling the flickable with mouse wheel)
Only when the button is pressed. In my case, rolling the wheel during this time is unlikely.


I'd try either subclassing QGraphicsProxyWidget or QPushButton and in there prevent Flickable for gettng its hands on the widget's events.
How can I disable Flickabel to filter its children event?
Do you mean connecting a slot to QPushButton pressed() signal and then disable Flickable to filter its children?
In my case, I have many QPushButton used in many Flickable. How can I manage that globally?

These questions might seem trivial. Sorry for that.

wysota
22nd August 2014, 10:33
How can I disable Flickabel to filter its children event?
First you'd need to see what it does to get those events.


Do you mean connecting a slot to QPushButton pressed() signal and then disable Flickable to filter its children?
No, the button itself would have to make sure its mouse move events are not intercepted/propagated to the Flickable. It is possible that providing an empty mouseMoveEvent() handler could be enough to do that however I'd have to look what Flickable does that breaks your program.


In my case, I have many QPushButton used in many Flickable. How can I manage that globally?
By C++ mechanism called "subclassing" :)

clousque
25th August 2014, 11:46
First you'd need to see what it does to get those events.
That is the kind of interrogation I'm having, but I don't know where to find the answer. I mean the Qt documentation is great for interface, but I find it hard to get explanations on the underlying mechanisms.
AFAIK the signals goes from child to parent, and if a child accepts it, the signal is not propagated to the parent. (Don't hesitate to correct me, I'm not totally confident on that). In my situtation, the signal is captured by Flickable before reaching the QPushButton (released signal while flick move started).


By C++ mechanism called "subclassing"
No comment :)

wysota
25th August 2014, 12:16
That is the kind of interrogation I'm having, but I don't know where to find the answer.
In the source code.