全屏鼠标释放事件
我有一个 pyqt 小部件,启动时会显示在所有窗口上。我需要它保持不关闭状态,直到用户决定这样做。是否可以在每次执行 mouseclick 时捕获鼠标释放事件,无论在何处完成:在 QtWidget 窗口内还是在 QtWidget 窗口外?
这是我使用的示例:
class Release_check(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.canvas = iface.mapCanvas()
self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
self.grid = QGridLayout()
self.grid.setSpacing(10)
self.setGeometry(500, 500, 400, 100)
self.text_out = QTextEdit()
self.setLayout(self.grid)
self.grid.addWidget(self.text_out, 0, 1, 1, 2)
self.show()
def mouseReleaseEvent(self, e):
screen_coordinate = f"x:{e.x()}, y:{e.y()}"
self.text_out.setText(screen_coordinate)
super(Release_check, self).mouseReleaseEvent(e)
app = Release_check()
I have a pyqt widget that is shown over all windows when launched. I need it to keep unclosed until user decides to. Is that possible to catch mouse release event every time mouseclick performed no matter where it was done: inside QtWidget window or outside of it?
Here is a sample I use:
class Release_check(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.canvas = iface.mapCanvas()
self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
self.grid = QGridLayout()
self.grid.setSpacing(10)
self.setGeometry(500, 500, 400, 100)
self.text_out = QTextEdit()
self.setLayout(self.grid)
self.grid.addWidget(self.text_out, 0, 1, 1, 2)
self.show()
def mouseReleaseEvent(self, e):
screen_coordinate = f"x:{e.x()}, y:{e.y()}"
self.text_out.setText(screen_coordinate)
super(Release_check, self).mouseReleaseEvent(e)
app = Release_check()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Qt 仅检测小部件内部的点击,如果您想检测小部件外部,则必须使用另一个使用操作系统资源来监视操作系统事件的库,例如 pyinput:
Qt only detects the click inside the widget, if you want to detect outside the widgets then you must use another library that uses OS resources to monitor OS events such as pyinput: