Solved ignoring qcloseevent before returning from function
-
i've seen in an existing code, when overriding closeEvent() of a window, such code:
void Window:closeEvent(QCloseEvent *event) { // some code... if(/* some condition */) { event->ignore(); return; } // some code... }
what is the purpose of event->ignore(); here, if we return from the function anyways?
-
Hi
"void QEvent::ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Clearing the accept parameter indicates that the event receiver does not want the event.
Unwanted events might be propagated to the parent widget." -
that's what the documentation says, but what exactly does "unwanted events might be propagated to the parent widget." mean? we can JUST return from the function and thus show that the event receiver didn't want the event, right? what is changed (besides the accepted flag to false) when ignore() is called?
-
@user4592357 said in ignoring qcloseevent before returning from function:
unwanted events might be propagated to the parent widget." mean?
It means that the event system will tell the widgets parent
about the event since the child widget did not
want it. You could also think like "Handled" about it.
So if you say , "I will handle it", its not sent to your parent.
But if you say , i wont handle it, the systems try the parents and and its parent etc.-
what is changed (besides the accepted flag to false) when ignore() is called ?
Nothing as far as i know. Its just a alias function for setAccepted(false) -
we can JUST return from the function
In theory yes. But in real life, its not the same as clearly stating i do not handle this event.
as Doc says
"It is set by default, but don't rely on this as subclasses may choose to clear it in their constructor."So do not count on it. Better to handle explicitly.
-