qevent - pyqt mouse held down eventfilter -
i new pyqt , can't figure out. trying install eventfilter when qpushbutton pressed , held down, system increments value @ rate (this qtimer). have second qpushbutton on same page when pressed , held, should decrememt value. system needs differentiate between single click , press , hold.here's have far, not bad confident there's more efficient way of doing this.
class app(qtgui.qmainwindow, app_ui_mainwindow): def __init__(self, parent=none): super(app, self).__init__(parent) qtgui.qmainwindow.__init__(self) app_ui_mainwindow.__init__(self) self.setupui(self) #set mouse , install event filter. self.mouse_state = app.mousebuttons() self.mouse_state == qtcore.qt.leftbutton self.increment_button.installeventfilter(self) self.decrement_button.installeventfilter(self) self.hoveringover = 'null' #timer when mouse held down. self.mouseheld = qtcore.qtimer() self.mouseheld.timeout.connect(self.update) self.mouseheld.start(500) #trigger every second. self.mouseheld.timeout.connect(self.mouse_held_event) #to figure out which/if hovering on button. def eventfilter(self, obj, event): if event.type() == qtcore.qevent.enter: self.hoveringover = obj.objectname() elif event.type() == qtcore.qevent.leave: self.hoveringover = 'null' return super(app, self).eventfilter(obj, event) def mouse_held_event(self): #set mouse. self.is_mouse_held = 1 self.mouse_state = app.mousebuttons() self.mouse_state == qtcore.qt.leftbutton if int(self.mouse_state) == 1: if self.hoveringover == 'increment_button': self.increment() elif self.hoveringover == 'decrement_button': self.decrement()
Comments
Post a Comment