Hwo to discard mousepressevent and mousemoveevent?



  • now . i clike a button to execute a function,but this function's execution efficiency is not high,so my code can break down ,when i clike mouse leftbutton continually in function's execution's process. thanke you



  • If your function is time consuming then you will get frozen GUI and nobody can click any button, thus you could not care ;)
    But to be serious you should delegate heavy work into separated thread, or use co-operative execution, and then: 1) you could disconnect the function for processing time, 2) you could set a flag which suppresses new processing, 3) you could use progress/throbber which blocks gui but doesn't freeze it.



  • Or at the start of the eventhandler, set a 'disable' button, at the end you will set a 'enable'. Only one event will be handled.



  • how to control eventLOOP.i use QApplication::processEvent() to do with mousePressEvent(),but when i clike leftbutton that produce mousePressEvent() ,my code will break down.

    how to control eventloop to diacard mouseevent.



  • [quote author="Bogdan" date="1385544352"]If your function is time consuming then you will get frozen GUI and nobody can click any button, thus you could not care ;)
    But to be serious you should delegate heavy work into separated thread, or use co-operative execution, and then: 1) you could disconnect the function for processing time, 2) you could set a flag which suppresses new processing, 3) you could use progress/throbber which blocks gui but doesn't freeze it.[/quote]

    how to blocks gui?.thank you.



  • You need to read more about Qt event loop mechanism and make sure you understand it. Your function is called by Qt gui event loop as a reaction on button click. If your function does heavy (time consuming) processing then it means it blocks event loop. It means it blocks gui refreshing, so it means your gui is frozen during this processing. Because of that I wrote that you need to delegate heave work into separate thread, or just do not block function called by gui event loop (you don't want to have frozen gui, do you?). Of course you can call processEvents periodically during this processing to force events processing, but IMHO it's not good solution and should be avoided.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.