python-3.xqt5pyqt5qgraphicsview

Disable mouse pointer in QGraphicsView


I want to disable the mouse pointer in a QGraphicsView.

What line of code do I need to add in the following example?

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

Solution

  • Qt::BlankCursor A blank/invisible cursor, typically used when the cursor shape needs to be hidden.

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