How can I catch a mouse hold event in either Qt or Qt Modeling Language? I don't mean hold as in press the button and wait a certain delay before emitting a signal. I mean a user clicks a button and while its not released I want it to emit signals so that I can, for example make an object follow the mouse position while its being held down.
The way i solved it was using a Timer event. Each time the Timer was triggered, id check if the mouse was pressed.
Related
How do i make a decreasing timer after pressing some button? Actually trying to maker in step event but the timer only decreases 1 per times which the button was pressed.
Just judging the functionality from the given information: you've set the timer in an event that you can only reach when a button is pressed.
If it only happens when you press the button, then that means the timer will only decrease if you either hold the button or click the button repeately.
A possible solution is to make a new boolean, and set that boolean to 'true' when the button is pressed. Then you make a new statement that checks if the boolean is true, and put the timer inside that statement.
Hopefully this helps.
I have a button which when clicked will run back-end process for, say, 10 sec.
I would like to make the button in pressed state till the process completes and then the button be released. This is, so that the user knows when the process is complete. As an example:
QString ExButtonStyleSheet = "QPushButton{background-color:lightgreen;}\
QPushButton:hover{background-color:yellow;}\
QPushButton:pressed{background-color:green;}\
QPushButton:disabled{background-color:grey;}";
In the above case, once clicked the button goes to hover state (yellow) even when the process is running (GUI is also busy) and turns lightgreen once free.
But this is not very explicit to the user, unlike the pressed state.(Note the above stylesheet is just an example and in my actual styesheet the hover state color is only slightly different from the normal.)
I am looking for a solution where the button remains to look pressed and only to be released when the process is complete.
You can theoretically use
QPushButton::setCheckable(true)
QPushButton::setDown(true) // Button is down
// Expensive task
QPushButton::setDown(false) // Button is released
Freezing the GUI for 10 seconds is a very bad idea.
You should use threads for your expensive tasks instead of blocking the GUI. Call QPushButton::setDown(true) and emit a signal to the thread which contains the code of the expensive task.
When the thread finishes the thread should call a slot in your MainWindow that contains QPushButton::setDown(false). This way your GUI will be fully responsive during the time and you follow the good coding behaviours.
My team is developing an UI for an apparatus with touch screen and we would like it to emit a sound (from a buzzer) each time the user correctly presses a button (so using the release event). Notice that I don't want to play the sound after each click on the interface, but only when the click is over a button.
We use many types of button, sometimes QPushButton and most of the times customized buttons derived from QAbstractButton. In most cases these buttons get an objectName.
So I supposed in order to do that, I would have to catch the MouseButtonRelease event and since I'm already working with a subclass of QApplication to handle excetions, I decided to do this in the notify function.
I tried, then, some methods to recognized when the MouseButtonRelease was related to a button but none of them were successfull. The best one, verifying the receiver's objectName was still not good enought not only because not all buttons had an objectName (which, of course, can be handled), but specially because not always the event was caught for buttons with names set. In other words, sometimes I would click in a button and it recognizes the event and sometimes I would click in the same button and the event is not recognized.
I did some research and another method I found was to set an event filter in the MainWindow, but not all widgets have the MainWindow as their parent which means I would have to Ctrl+c / Ctrl+V the same code time after time when I obviously want something more localized (i.e. in only one spot).
So why it happens that the notify not always handles the events? And how could I do this? Any suggestions are appreciated specially one that is less heavier then handling the events globally.
As info, the other two ways I tried to catch the events with similar or even worst results inside notify were with receiver->inherits("...") and qobject_cast< QAbstractButton* >(receiver).
My program is working on Qt, and I have a problem and there is free answer for it in website.
Our products need to update image while user move mouse, but the updating image is very time-consuming.If user move the mouse quickly, the system will generate a lot of mouse movement events, eventually leading to clogging of the background process.Therefore, we need to filter out part of the event.
I filter mouse move event by insert event filter in QApplication:
qApp->insertEventFilter(this)
Once I catch mouse event, I will store QMouseEvent and pointer of QObject, and active QTimer. other mouseMouseEvent will can overwrite them before timeout. After timeout, the last event will be post.
I can't use:
QApplication::sendEvent(XX) or postEvent(xx)
because it will be catched by my event filter again.
How can I make it work?
Don't filter the events. Instead of that, change your background worker which is responsible for producing the data to make sure that you do not spend time on stuff you won't need.
I´am trying to create my own custom list component in a Flex mobile Project which fires an Event when the user touches a listitem and holds the finger down for a given time.
Some kind of "longTouch"-Event like its implemented on native android listitems to edit the entry for example.
I tried to listen for the MOUSE_DOWN Event to start a timer and dispatch an event when the timer finished. But this approach failed because i cant get the listitem that was pressed by the user because the List component updates the "selectedItem"-property only after the user lifts his finger from the list.
thanks in advance
Andre Uschmann
There is no longTouch (or longPress) event exposed through the Flash Player Native APIs.
One option is to roll your own using TOUCH_BEGIN, TOUCH_END, and a timer.
Basically:
When user starts the touch, start the timer.
When the touch_End event fires; check the timer to see how long it has been running using currentCount. If it is long enough to be considered a "long touch", then dispatch your custom longPress event. If not; then stop the timer and ignore.
This could all happen inside the renderer; so you'd know exactly what item was pressed.
I expect this would be more solid than using mouse events, which seem to be inconsistent on touch based devices