In this article we will see how we can get tool tip text of the label part of scroll label, when know we can make scrollable label with the help of inheriting a scroll class and making label in it, but when we set tool tip to the class object tooltip is set to the whole widget i.e label and the scroll bar as well. In order to add tool tip the label part only we have to override the functions of the object.
Steps for implementations –
1. Create a new class which inherits QScrollArea
2. Inside the class create vertical layout
3. Create a label and make it multi-line and add it to the layout
5. Over-ride the setText and text method for label
6. Over-ride setToolTip method to add tooltip to the label and toolTip method to get the tool tip
7. Create object of this class inside the main window class and setting text to it
8. Add tooltip to the object with the help ofsetToolTipmethod
9. Retrieve the tooltip text with the help oftoolTipmethod
10. Create another label to show the tooltip text
Below is the implementation
# importing libraries from PyQt5.QtWidgets import * from PyQt5 import QtCore, QtGui from PyQt5.QtGui import * from PyQt5.QtCore import * import sys # class for scrollable label class ScrollLabel(QScrollArea): # constructor def __init__(self, *args, **kwargs): QScrollArea.__init__(self, *args, **kwargs) # making widget resizable self.setWidgetResizable(True) # making qwidget object content = QWidget(self) self.setWidget(content) # vertical box layout lay = QVBoxLayout(content) # creating label self.label = QLabel(content) # making label multi-line self.label.setWordWrap(True) # adding label to the layout lay.addWidget(self.label) # the setText method def setText(self, text): # setting text to the label self.label.setText(text) # getting text method def text(self): # getting text of the label get_text = self.label.text() # return the text return get_text # overriding setToolTip method def setToolTip(self, text): # setting tool tip to the label self.label.setToolTip(text) # overriding toolTip method def toolTip(self): # returning tool tip text return self.label.toolTip() class Window(QMainWindow): def __init__(self): super().__init__() # setting title self.setWindowTitle("Python ") # setting geometry self.setGeometry(100, 100, 600, 400) # calling method self.UiComponents() # showing all the widgets self.show() # method for widgets def UiComponents(self): # text to show in label text = "There are so many options provided by Python to develop GUI " \ " There are so many options provided by Python to develop GUI" \ " There are so many options provided by Python to develop GUI" # creating scroll label label = ScrollLabel(self) # setting text to the label label.setText(text) # setting geometry label.setGeometry(100, 100, 150, 80) # setting tool tip label.setToolTip("It is tool tip") # getting the tool tip tip = label.toolTip() # creating another label to show the tool tip result = QLabel("Tool tip : " + tip, self) # setting geometry to the label result.setGeometry(150, 200, 200, 30) # create pyqt5 app App = QApplication(sys.argv) # create the instance of our Window window = Window() # start the app sys.exit(App.exec()) |
Output :

Recommended Posts:
- PyQt5 Scrollable Label – Setting tool tip duration to label part
- PyQt5 Scrollable Label – Getting tool tip duration of the label part
- PyQt5 Scrollable Label - Setting tool tip to the label part
- PyQt5 Scrollable Label – Getting tool tip duration
- PyQt5 Scrollable Label - Setting tool tip
- PyQt5 Scrollable Label – Setting tool tip duration
- PyQt5 - Getting text of scrollable label
- PyQt5 Scrollable Label - Retrieving tooltip text
- PyQt5 - Scrollable Label
- PyQt5 – Access tool tip duration of label | ToolTipDuration method
- PyQt5 – How to change size of the Label | label.resize method
- PyQt5 Label – Checking if label is widget type
- PyQt5 Label – Checking if label is window type
- PyQt5 – How to hide label | label.setHidden method
- PyQt5 – How to align Text of Label
- PyQt5 – What's this help text for Label | setWhatsThis() method
- PyQt5 – How to change font and size of Label text ?
- PyQt5 – How to change text of pre-existing label | setText method
- PyQt5 QSpinbox - Dragging text from it and dropping it to Custom Label
- PyQt5 – How to get Label coordinates ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

