我想禁用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_())
答案 0 :(得分:2)
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_())