QStatusBar message disappears on menu hover

2024/10/11 16:29:28

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.

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.

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

I got the same problem, and I found another way which is creating a new QLabel

self.myMessage = QtGui.QLabel()
self.myMessage.setText("Hello")

and add it as an widget to the status bar on the left

self.statusBar.addWidget(self.myMessage)

or on the right

self.statusBar.addPermanentWidget(self.myMessage)
https://en.xdnf.cn/q/69757.html

Related Q&A

How to eliminate a python3 deprecation warning for the equality operator?

Although the title can be interpreted as three questions, the actual problem is simple to describe. On a Linux system I have python 2.7.3 installed, and want to be warned about python 3 incompatibiliti…

Cannot get scikit-learn installed on OS X

I cannot install scikit-learn. I can install other packages either by building them from source or through pip without a problem. For scikit-learn, Ive tried cloning the project on GitHub and installin…

Decompressing a .bz2 file in Python

So, this is a seemingly simple question, but Im apparently very very dull. I have a little script that downloads all the .bz2 files from a webpage, but for some reason the decompressing of that file is…

Why does Pandas coerce my numpy float32 to float64?

Why does Pandas coerce my numpy float32 to float64 in this piece of code:>>> import pandas as pd >>> import numpy as np >>> df = pd.DataFrame([[1, 2, a], [3, 4, b]], dtype=np…

Conda and Python Modules

Sadly, I do not understand how to install random python modules for use within iPython Notebooks with my Anaconda distribution. The issue is compounded by the fact that I need to be able to do these t…

WeakValueDictionary retaining reference to object with no more strong references

>>> from weakref import WeakValueDictionary >>> class Foo(object): ... pass >>> foo = Foo() >>> db = WeakValueDictionary() >>> db[foo-id] = foo >>…

Using pretrained glove word embedding with scikit-learn

I have used keras to use pre-trained word embeddings but I am not quite sure how to do it on scikit-learn model.I need to do this in sklearn as well because I am using vecstack to ensemble both keras s…

Is there an easy way to tell how much time is spent waiting for the Python GIL?

I have a long-running Python service and Id like to know how much cumulative wall clock time has been spent by any runnable threads (i.e., threads that werent blocked for some other reason) waiting for…

Inverse filtering using Python

Given an impulse response h and output y (both one-dimensional arrays), Im trying to find a way to compute the inverse filter x such that h * x = y, where * denotes the convolution product.For example,…

Quadruple Precision Eigenvalues, Eigenvectors and Matrix Logarithms

I am attempting to diagonalize matrices in quadruple precision, and to take their logarithms. Is there a language in which I can accomplish this using built-in functions?Note, the languages/packages i…