Open In App

PyQt5 – Setting and accessing WHATS THIS help text for Status Bar

Last Updated : 26 Mar, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

n PyQt5 there are lots of widgets and bars and when we tend to make an application, we end up putting lots of windows and for each window there exit status bar. Sometimes we can’t remember why this status bar is used and what is this status bar. That’s why for back-end purposes PyQt5 allows us to set help text. In this article we will see how to set and access help text for status bar.

In order to set help text we use setWhatsThis() method and for accessing the help text we use whatsThis() method.

Syntax :

self.statusBar().setWhatsThis()
self.statusBar().whatsThis()

Argument :
setWhatsThis() takes string as argument.
whatsThis() takes no argument.

Return :
setWhatsThis() return None
whatsThis() returns string.

Code:




from PyQt5.QtCore import * 
from PyQt5.QtGui import * 
from PyQt5.QtWidgets import * 
import sys
  
  
class Window(QMainWindow):
    def __init__(self):
        super().__init__()
  
        # set the title
        self.setWindowTitle("Python")
  
        # setting  the geometry of window
        self.setGeometry(60, 60, 600, 400)
  
        # setting status bar message
        self.statusBar().showMessage("This is status bar")
  
        # setting  border
        self.statusBar().setStyleSheet("border :3px solid black;")
  
        # setting help text
        self.statusBar().setWhatsThis("this is help text for status bar")
  
        # creating a label widget
        self.label_1 = QLabel(self)
  
        # moving position
        self.label_1.move(100, 100)
  
        # setting up the border
        self.label_1.setStyleSheet("border :1px solid blue;")
  
        # accessing help text of status bar
        help = self.statusBar().whatsThis()
  
        # setting text to label
        self.label_1.setText(help)
  
        # resizing label
        self.label_1.adjustSize()
  
        # show all the widgets
        self.show()
  
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())


Output :



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads