在 QGraphicsView 中禁用鼠标指针

问题描述 投票:0回答:2

我想在 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_())
python-3.x qt5 pyqt5 qgraphicsview
2个回答
5
投票

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

0
投票

在 PyQt6 中

self.setCursor(Qt.CursorShape.BlankCursor)
© www.soinside.com 2019 - 2024. All rights reserved.