Skip to content

PyQt QLabel which can resize the font responsively accordance with window's size change

License

Notifications You must be signed in to change notification settings

yjg30737/pyqt-responsive-label

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyqt-responsive-label

PyQt QLabel which can resize the font responsively accordance with window's size change

Requirements

  • PyQt5 >= 5.8

Setup

python -m pip install pyqt-responsive-label

Method Overview

  • setAcceptTextChange(f: bool) - Choose the option that this should accept text change(paintEvent) or not.

Example

from PyQt5.QtWidgets import QApplication, QVBoxLayout, QWidget
from pyqt_responsive_label import ResponsiveLabel


class Widget(QWidget):
    def __init__(self):
        super().__init__()
        self.__initUi()

    def __initUi(self):
        responsiveLabel = ResponsiveLabel(self)
        responsiveLabel.setText('ABC')

        lay = QVBoxLayout()
        lay.addWidget(responsiveLabel)

        self.setMinimumSize(responsiveLabel.sizeHint())
        self.setLayout(lay)


if __name__ == "__main__":
    import sys

    app = QApplication(sys.argv)
    widget = Widget()
    widget.show()
    app.exec_()

Result

Like below, label font size is changing accordance with window's size.

image

image

Note: Since v0.0.3, text is smaller than result image above for avoiding excessive width problem.

See Also