How to know when the hide() of a QWebView is effective?
-
Hello,
I want to know when the QWebView is hidden in the screen, that is because I want to suspend the process after that, and if I suspend before, the QWebView is shown (until restarted or killed the process).
I have tried:
- Suspend the process after the hideEvent(), but it did not work.
- Put a sleep between the hide() and the suspend(), It work but with sleep(1), 1 second.
- call suspend() with a QTimer single shot, It work but with a delay of 200ms minimun.
- Also, repaint(), update(), does not work. That's because when you hide() the window the paintEvent() is not called anymore. So I cannot allign there the suspend().
- Another partial solution, processEvents() and then sched_yield() before the suspend(). unfortunately it fail also (with less probability)
I would want to call the suspend() just after the QwebView is effectively hidden. Is this posible?
Thanks.
-
Hi and welcome to the forums.
Im a bit surprised hideEvent didnt work.
Did u remember to forward it to the base class?Also, did u check if IsVisible() reflect the status correctly in your use case?
-
Hi,
Thanks you very much for your help. This is a basic pseudo-code using the hideEvent():class myClass : public QWebView { public: myClass(infoStruct *data, QWidget * parent = 0); ~myClass(); void show(); void hide(int hid); protected: virtual void hideEvent(QHideEvent * event); (...) void myClass::show() { this->setVisible(true); } void myClass::hide(int hid) { this->setVisible(false); } void myClass::internalHide(int hid) { hide(hid); } void myClass::hideEvent(QHideEvent * event) { QWebView::hideEvent(event); emit hideFinished(); } }; class myProcess { (...) int main() { internalHide(hid); waitSignal(hideFinished); processSuspend(); } };
As I have researched, the hide is not effective (hidden in the screen) when the hideEvent is called, as the showEvent is not effective until the repaint loop. So, I put it (the suspend) in the paintEvent. But unfortunately, the hide() will never trigger the paintEvent, not even once.
My problem here is that sometimes, the process go to suspend quicker than the hide is effective. It cause that the window is not hidden until resume or kill the process. And the only solution seems to be using a delay.
As you suggest, I had tried waiting for the isVisible()==false, but it was still happening with a similar probability.