当用户按下并按住而不是仅按下时,如何修改要触发的过滤器?我有一些工作,但它没有完全包含在过滤器中,它变得混乱。我无法弄清楚如何确定用户是否按住按钮一段时间而不阻止UI线程
def holdable(widget):
class Filter(QObject):
clicked = pyqtSignal()
def eventFilter(self, obj, event):
if obj == widget:
if event.type() == QEvent.MouseButtonPress:
if obj.rect().contains(event.pos()):
self.clicked.emit()
return True
return False
filter = Filter(widget)
widget.installEventFilter(filter)
return filter.clicked
答案 0 :(得分:1)
一旦我想到它就不那么难了,但这里是
<body>
<center>
<img id="Title" src="http://i.imgur.com/AANaMuQ.png">
</center>
<div class="para1">
<h3>Plot Summary</h3>
The future of civilization rests in the fate of the One Ring, which has been lost for centuries. Powerful forces are unrelenting in their search for it. But fate has placed it in the hands of a young Hobbit named Frodo Baggins, who inherits the Ring and steps into legend. A daunting task lies ahead for Frodo when he becomes the Ringbearer - to destroy the One Ring in the fires of Mount Doom where it was forged.
<br>
</div>
<div class="para2">
<h3>Inputs</h3>
<form>
<p>Input your character's name here:</p>
<input type="text" id="a" />
<p>Choose your character's role:</p>
<input type="radio" name="role" id="RB">Ringbearer</input>
<br>
<input type="radio" name="role" id="M">Wizard</input>
<br>
<input type="radio" name="role" id="E">Evil Overlord</input>
<br>
<br>
<input value="Begin Your Journey" type="button" onclick="STORYNAME()">
</form>
</div>
<div class="para2">
<br>
<img id="img1" src="shire5.jpg">
<p id="story">ASDASDASD.</p>
</div>
</body>
你可以通过这样做把它挂钩到一个小部件上:
def holdable(widget):
class Filter(QObject):
clicked = pyqtSignal(QWidget)
def eventFilter(self, obj, event):
if obj == widget:
if event.type() == QEvent.MouseButtonPress:
if obj.rect().contains(event.pos()):
obj.heldDown = datetime.datetime.now()
#return True
elif event.type() == QEvent.MouseButtonRelease:
if obj.rect().contains(event.pos()):
if(obj.heldDown):
diff = datetime.datetime.now() - obj.heldDown
obj.heldDown = None
if(diff.total_seconds() > 1):
self.clicked.emit(obj)
return True
return False
filter = Filter(widget)
widget.installEventFilter(filter)
return filter.clicked