Qt user resize event ends (stops)

后端 未结 5 1509
后悔当初
后悔当初 2021-02-10 03:19

I have a QWidget and i need to do some actions (refresh a picture in widget) when resize event ends. How can i catch this action? I need to catch moment when user ENDs all his r

5条回答
  •  眼角桃花
    2021-02-10 03:43

    I've do it in this way:

    1. inherit my class from QWidget
    2. define private variable int timerId = 0
    3. overload QWidget::resizeEvent and QObject::timerEvent

    void MapLoader::resizeEvent(QResizeEvent *){
        if (timerId){
            killTimer(timerId);
            timerId = 0;
        }
        timerId = startTimer(5000/*delay beetween ends of resize and your action*/);
    }
    
    void MapLoader::timerEvent(QTimerEvent *te){
        /*your actions here*/
        killTimer(te->timerId());
        timerId = 0;
    }
    

提交回复
热议问题