在QGraphicsView中禁用鼠标指针

时间:2019-01-29 21:13:00

标签: python-3.x qt5 pyqt5 qgraphicsview

我想禁用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_())

1 个答案:

答案 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_())