8.QObject 定时器
2019-05-08 18:30
1621 查看
[code]class MyObject(QObject): # 继承QObject def timeEvent(self, evt): # 重写 timeEvent方法 print('1', evt) app = QApplication(sys.argv) window = QWidget() window = setWindowTitle('QObject定时器的使用') window.resize(500, 500) obj = MyObject() timer_id = obj.startTimer(1000) # 执行事件 obj.killTimer(timer_id)
案例1
[code]class MyLabel(QLabel): def __init__(self, *args, **kwargs): super().__init__() self.setText('10') self.move(100, 100) self.setStyleSheet('font-size: 22px;') self.timer_id = self.startTimer(1000) def timeEvent(self, *args, **kwargs): print('XX') current_sec = int(self.text()) current_sec -= 1 self.steText(str(current_sec)) if current_sec == 0: print('stop') self.killTimer(self.timer_id) app = QAoolication(sys.argv) window = QWidget() window.setWindowTitle('QObject定时器的使用') window.resize(500, 500) label = MyLabel(window) window.show() sys.exit(app.exec_())
[code]class MyLabel(QLabel): def __init__(self, *args, **kwargs): super().__init__() self.setText('10') self.move(100, 100) self.setStyleSheet('font-size: 22px;') self.timer_id = self.startTimer(1000) def setSec(self, sec): self.setText(str(sec)) def startMyTimer(self, ms): self.timer_id = self.startTimer(ms) def timeEvent(self, *args, **kwargs): print('XX') current_sec = int(self.text()) current_sec -= 1 self.steText(str(current_sec)) if current_sec == 0: print('stop') self.killTimer(self.timer_id) app = QAoolication(sys.argv) window = QWidget() window.setWindowTitle('QObject定时器的使用') window.resize(500, 500) label = MyLabel(window) label.setSec(5) label.startMyTimer(2000) window.show() sys.exit(app.exec_())
案例2
[code]class MyWidget(QWidget): def __init__(self, *args, **kwargs): super().__init__() self.setWindowTitle('QObject定时器的使用') self.resize(500, 500) self.timer_id = self.startTimer(1000) def timeEvent(self, *args, **kwargs): current_w = self.width() current_h = self.height() self.resize(current_w + 10, current_h + 10) app = QAoolication(sys.argv) window = Mywidget() window.show() sys.exit(app.exec_())
相关文章推荐
- Qt中使用定时器(可使用QObject::timerEvent定时执行,QTimer::singleShot可只触发一次)
- Qt中使用定时器(可使用QObject::timerEvent定时执行,QTimer::singleShot可只触发一次)
- Qt中使用定时器(可使用QObject::timerEvent定时执行,QTimer::singleShot可只触发一次)
- QT定时器的两种应用(QObject就有timerEvent事件,一种什么样的居心呢?)
- Qt分析:Qt中的两种定时器(可是QObject为什么要提高定时器呢,没必要啊。。。)
- NS2 定时器:BackoffTimer/ DeferTimer/NavTimer/RxTimer/TxTimer/IFTimer
- js 中的定时器 例子
- 定时器中断
- Java定时器之Timer源码剖析
- Linux下的定时器
- spring Schedule 定时器表达式详解
- spring的定时器
- Spring定时器设置详解释
- MFC的DLL中实现定时器功能
- Zstack协议栈--系统时钟定时器
- [转]Linux中定时器的算法实现
- spring,定时器代码
- 使用高级定时器,定时器1遇到的问题
- 两种spring的定时器的实现
- 内核中的定时器