gpt4 book ai didi

python-3.x - 在 QGraphicsView 中禁用鼠标指针

转载 作者:行者123 更新时间:2023-12-04 14:21:21 25 4
gpt4 key购买 nike

我想在 QGraphicsView 中禁用鼠标指针。

我需要在下面的例子中添加哪一行代码?

import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QGraphicsView


class GraphicsWindow(QGraphicsView):
def __init__(self, parent=None):
super().__init__(parent)
self.showFullScreen()

def keyPressEvent(self, event):
if event.key() == Qt.Key_Escape:
self.close()


if __name__ == "__main__":
app = QApplication(sys.argv)
graphics_window = GraphicsWindow()
graphics_window.show()
sys.exit(app.exec_())

最佳答案

Qt::BlankCursor空白/不可见光标,通常在需要隐藏光标形状时使用。

import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QGraphicsView

class GraphicsWindow(QGraphicsView):
def __init__(self, parent=None):
super().__init__(parent)
self.showFullScreen()

self.setCursor(Qt.BlankCursor) # < ------

def keyPressEvent(self, event):
if event.key() == Qt.Key_Escape:
self.close()

if __name__ == "__main__":
app = QApplication(sys.argv)
graphics_window = GraphicsWindow()
graphics_window.show()
sys.exit(app.exec_())

关于python-3.x - 在 QGraphicsView 中禁用鼠标指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54429657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com