Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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_())
like image 988
Atalanttore Avatar asked Sep 13 '25 04:09

Atalanttore


1 Answers

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_())
like image 93
S. Nick Avatar answered Sep 14 '25 19:09

S. Nick