Important: Please read the Qt Code of Conduct -

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:

    1. Suspend the process after the hideEvent(), but it did not work.
    2. Put a sleep between the hide() and the suspend(), It work but with sleep(1), 1 second.
    3. call suspend() with a QTimer single shot, It work but with a delay of 200ms minimun.
    4. 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().
    5. 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?


  • Lifetime Qt Champion

    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
    		myClass(infoStruct *data, QWidget * parent = 0);
    		void show();
    		void hide(int hid);
            virtual void hideEvent(QHideEvent * event);
    void myClass::show()
    void myClass::hide(int hid)
    void myClass::internalHide(int hid)
    void myClass::hideEvent(QHideEvent * event)
    	emit hideFinished();
    class myProcess
    int main()

    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.

Log in to reply