QStatusBar 消息在菜单悬停时消失 [英] QStatusBar message disappears on menu hover

查看:51
本文介绍了QStatusBar 消息在菜单悬停时消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的 QMainWindow 应用程序,其中包含一个 menubar 和一个 statusbar.当我将鼠标悬停在菜单上时,状态消息消失.更准确地说,状态消息被清除.我不知道是什么导致了这种行为,但它导致了我希望成为微不足道的行为的非常困难的解决方法.

I have a very basic QMainWindow application that contains a menubar and a statusbar. When I hover over the menu the status message disappears. More precisely, the status message is cleared. I have no idea what is causing this behavior but it's resulting in a very difficult workaround for what I hoped to be trivial behavior.

这是有问题的,原因如下:我可以通过向 QStatusBar 添加一个 QLabel 小部件来使消息永久化,但是我得到了尴尬的边框.我不要边界.我知道如何移除边框的唯一方法是通过 QStatusBar.setStyleSheet().我正在为我的配色方案使用调色板,而不是样式表,因此修改样式表会弄乱其他颜色.当我通过样式表进行修改时,我也无法恢复原始的 statusBar QLabel 颜色.我不是最擅长使用样式表.

This is problematic for the following reason: I can make the message permanent by adding a QLabel widget to the QStatusBar, but then I get the awkward border. I don't want the border. The only way I know how to remove the border is via QStatusBar.setStyleSheet(). I am using a palette for my color scheme as opposed to a stylesheet so modifying the stylesheet messes up other colors. I also can't restore the original statusBar QLabel color when I make a modification via the stylesheet. I'm not the best at using stylesheets.

有没有办法阻止菜单交互清除状态消息?如果没有,有没有办法在添加 QLabel 小部件时从 StatusBar 中删除边框,同时保留我的调色板(可能不是通过样式表)?

Is there a way to prevent the menu interaction from clearing the status message? If not, is there a way to remove the border from the StatusBar when adding a QLabel widget while preserving my palette (maybe not via stylesheets)?

#!/usr/bin/env python
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class win(QMainWindow):
    def __init__(self,parent=None):
        super(win,self).__init__(parent)
        self.menubar = QMenuBar(self)
        self.fileMenu  = QMenu("File")
        self.exitAction = QAction("Exit",self)
        self.fileMenu.addAction(self.exitAction)
        self.menubar.addMenu(self.fileMenu)   
        self.statusBar().showMessage("Hello")
        self.connect(self.exitAction,SIGNAL("triggered()"), self.close)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    GUI = win()
    GUI.show()
    app.exec_()

推荐答案

基本上,您悬停在上面的每个小部件都会将状态栏文本设置为其 statusTip 属性,即使该属性是空字符串也是如此.

Basically, each widget you hover over sets the status bar text to their statusTip property even when that property is an empty string.

对于 QMenu,文本存储在 menuAction 操作状态提示中,因此,您可以使用文本而不是仅使用以下内容清除状态栏:

For QMenu, the text is stored in the menuAction action status tip, so, you can have a text instead of just clearing the status bar with something like this:

self.fileMenu.menuAction().setStatusTip("File Menu is hovered")

为了防止任何改变状态栏的事情,你可以在状态栏上安装一个 eventFilter 并过滤掉所有的 QStatusTipEvent.

To prevent anything to change the status bar, you can probably install an eventFilter on the status bar and filter out all QStatusTipEvent.

这篇关于QStatusBar 消息在菜单悬停时消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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