Atalanttore
Atalanttore

Reputation: 349

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

Upvotes: 4

Views: 2972

Answers (2)

Evan Thomas
Evan Thomas

Reputation: 411

In PyQt6

self.setCursor(Qt.CursorShape.BlankCursor)

Upvotes: 1

S. Nick
S. Nick

Reputation: 13701

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

Upvotes: 6

Related Questions