问题描述
这是我到目前为止所拥有的
timer = new QTimer(this);
connect(timer,&QTimer::timeout,this,[&slider,sliderdisplay]() {
// increment slider value and update display,reset to min slider value once at max
});
timer->start(50);
如何通过单击按钮小部件来暂停/恢复该计时器?
解决方法
没有直接的方法来暂停/继续。当您看到docs时,会发现您只是可以开始/停止。但是,如果您决定更进一步,则可以使用其剩余时间()方法读取间隔的剩余时间。
对于单击操作,它非常简单。 QPushButton提供clicked()信号,您只需将其连接到自己的插槽,将剩余时间存储在某个位置,然后再次单击将值插入QTimer的start()方法。