In this article we will see how we can set tooltip duration to the scroll-able label. By default when we create a label all the text is in the single line and if length of text is greater than label, extra text didn’t show, although with the help of setWordWrap method we can create a multi-line label but still if the text exceeds it will not show in the label. In order to show whole text in a small label we have to make label scroll-able, in order to do this we have to make our own scrollable label class which inherits the QScrollArea class which allows to us to make label scroll-able.
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. Create object of this class inside the main window class and setting text to it 7. Add tooltip to the object with the help of setToolTip method 8. Add tooltip duration to the object with the help of setToolTipDuration method
Below is the implementation
Python3
| # importing librariesfromPyQt5.QtWidgets import*fromPyQt5 importQtCore, QtGuifromPyQt5.QtGui import*fromPyQt5.QtCore import*importsys# class for scrollable labelclassScrollLabel(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    defsetText(self, text):        # setting text to the label        self.label.setText(text)    # getting text method    deftext(self):        # getting text of the label        get_text =self.label.text()        # return the text        returnget_textclassWindow(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    defUiComponents(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 istool tip")        # setting tool tip duration        label.setToolTipDuration(1000)# create pyqt5 appApp =QApplication(sys.argv)# create the instance of our Windowwindow =Window()# start the appsys.exit(App.exec()) | 
Output : 

 
                                    







