无法改变光标形状
当将右鼠标按钮按下工具栏上的按钮小部件时,我正在尝试更改光标的形状。这是一个代码段:
def eventFilter(self, obj, event): # QEvent
if isinstance(obj, QPushButton):
et = event.type()
if et == QEvent.Type.MouseButtonPress:
if event.button() == Qt.MouseButton.RightButton:
cur_cursor = self.toolbar_tables.cursor() # QCursor
if cur_cursor.shape() == Qt.CursorShape.ArrowCursor:
cur_cursor.setShape(Qt.CursorShape.OpenHandCursor)
else:
cur_cursor.setShape(Qt.CursorShape.ArrowCursor)
return True
达到了第一个set -shape方法,但是即使光标不会更改,即使第一个setShape确实可以在内部正确更改形状,也从未达到第二个set -shape方法。 QT系统似乎有效,因为如果我在右按钮上按下拖动操作,光标会更改为黑色敞开的手。
请任何想法。
编辑:
def eventFilter(self, obj, event): # QEvent
if isinstance(obj, QPushButton):
et = event.type() # int
if et == QEvent.Type.MouseButtonPress:
if event.button() == Qt.MouseButton.RightButton:
cur_cursor = self.toolbar_tables.cursor() # QCursor
if cur_cursor.shape() == Qt.CursorShape.ArrowCursor:
cur_cursor.setShape(Qt.CursorShape.OpenHandCursor)
else:
cur_cursor.setShape(Qt.CursorShape.ArrowCursor)
self.toolbar_tables.setCursor(cur_cursor)
# QGuiApplication.setOverrideCursor(cur_cursor)
return True
I am trying to change the shape of the cursor when the right mouse button is pressed over a pushbutton widget on a toolbar. Here's a code snippet:
def eventFilter(self, obj, event): # QEvent
if isinstance(obj, QPushButton):
et = event.type()
if et == QEvent.Type.MouseButtonPress:
if event.button() == Qt.MouseButton.RightButton:
cur_cursor = self.toolbar_tables.cursor() # QCursor
if cur_cursor.shape() == Qt.CursorShape.ArrowCursor:
cur_cursor.setShape(Qt.CursorShape.OpenHandCursor)
else:
cur_cursor.setShape(Qt.CursorShape.ArrowCursor)
return True
The first setShape method is reached, but the second is never reached because the cursor doesn't change, even though the first setShape does correctly change the shape internally. The Qt system seems to work because if I start a drag operation upon a right button press, the cursor changes to a black open hand.
Any ideas, please.
Edit:
def eventFilter(self, obj, event): # QEvent
if isinstance(obj, QPushButton):
et = event.type() # int
if et == QEvent.Type.MouseButtonPress:
if event.button() == Qt.MouseButton.RightButton:
cur_cursor = self.toolbar_tables.cursor() # QCursor
if cur_cursor.shape() == Qt.CursorShape.ArrowCursor:
cur_cursor.setShape(Qt.CursorShape.OpenHandCursor)
else:
cur_cursor.setShape(Qt.CursorShape.ArrowCursor)
self.toolbar_tables.setCursor(cur_cursor)
# QGuiApplication.setOverrideCursor(cur_cursor)
return True
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论