user1054424 user1054424 - 1 year ago 117
Python Question

QStatusBar message disappears on menu hover

I have a very basic

application that contains a
and a
. 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.

This is problematic for the following reason:
I can make the message permanent by adding a
widget to the
, 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
. 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.

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):
self.menubar = QMenuBar(self)
self.fileMenu = QMenu("File")
self.exitAction = QAction("Exit",self)
self.connect(self.exitAction,SIGNAL("triggered()"), self.close)

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

Answer Source

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

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")

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