QDialog:按下问号 (?) 时出现禁止光标 [英] QDialog: Forbidden Cursor appears when Question Mark (?) Pressed

查看:56
本文介绍了QDialog:按下问号 (?) 时出现禁止光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在基于 QDialog 的应用程序中使用WhatsThis"功能,因此当用户单击标题栏中的小问号时,会出现一个关于"对话框.

I am trying to get the 'WhatsThis' functionality working in a QDialog-based application, so when the user clicks the little question mark in the Title Bar, a little 'about' dialog appears.

默认情况下,除了将鼠标光标更改为禁止"光标外,单击该按钮不会执行任何操作:

By default, clicking that button does nothing except change my mouse cursor to the 'Forbidden' cursor:

基于之前的帖子,我重新实现事件如下:

Based on a previous post, I reimplemented event as follows:

def event(self, event): 
    if event.type() == QtCore.QEvent.EnterWhatsThisMode:
        print "Here is a useful message"
        return True
    return QtGui.QDialog.event(self, event)

虽然这会打印出所需的消息,但即使我将以下内容添加到上述事件函数中,我仍然得到禁止"光标:

While this prints out the desired message, I still get the 'Forbidden' cursor, even when I add the following to the above event function:

QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))

这会临时创建一个箭头,但是当我将光标移到应用程序标题栏之外的任何位置时,光标再次变为禁止.这几乎就像在某处打开了一个需要执行的模态对话框一样.

This creates an arrow temporarily, but when I bring the cursor anywhere outside the Title Bar in the app, the cursor turns Forbidden again. It's almost as if it is acting like there is a modal dialog open somewhere that needs to be executed.

如何阻止这种被禁止的行为?

How can I stop this Forbidden behavior?

推荐答案

插入对 QWhatsThis.leaveWhatsThisMode() 在您的事件处理程序中退出这是什么?"进入后立即进入模式.

Insert a call to QWhatsThis.leaveWhatsThisMode() in your event handler to exit "What's this?" mode as soon as it's entered.

def event(self, event): 
    if event.type() == QtCore.QEvent.EnterWhatsThisMode:
        QtGui.QWhatsThis.leaveWhatsThisMode()
        print "Here is a useful message"
        return True
    return QtGui.QDialog.event(self, event)

这篇关于QDialog:按下问号 (?) 时出现禁止光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆