In this article we will see how we can get the text of the scroll-able label, we can create a scroll-able label with the help of making new class which inherits scroll area class but the problem arises the new class can only set the text we can’t get the text as it is scroll-able label class object not the normal label object.
In order to retrieve the text from scrollable label, do the following –
1. Create a scroll-able label class which inherits QScrollArea
2. Add layout and add label to the label
3. Make set text function which adds text to the label
4. Create a text function which returns the content of the label
Scroll Label Class Syntax :
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) # setting alignment to the text self.label.setAlignment(Qt.AlignLeft | Qt.AlignTop) # 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
Below is the implementation
- PyQt5 Scrollable Label - Getting tool tip text of the label part
- PyQt5 Scrollable Label - Retrieving tooltip text
- 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
- PyQt5 Scrollable Label - Setting tool tip
- PyQt5 Scrollable Label – Getting tool tip duration
- PyQt5 Scrollable Label – Setting tool tip duration
- 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 change size of the Label | label.resize method
- PyQt5 Label – Checking if label is window type
- PyQt5 Label – Checking if label is widget type
- PyQt5 – How to hide label | label.setHidden method
- PyQt5 - Add Label to StatusBar
- 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 firstname.lastname@example.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.