Skip to main content

PyQt QLabel which supports SVG icon

Project description

pyqt-svg-label

PyQt QLabel which supports SVG icon

This is useful to set svg icon.

If you want to use button which supports SVG icon, see pyqt-svg-icon-pushbutton.

Requirements

  • PyQt5 >= 5.8

Setup

python -m pip install pyqt-svg-label

Usage

  • setSvgFile(filename: str) to set svg file.

Included Packages

  • qtpy - Make this module support not only PyQt5 but also PyQt6, PySide2, PySide6

  • absresgetter

Example

Code Sample

from PyQt5.QtWidgets import QLabel, QHBoxLayout, QApplication, QWidget

from pyqt_svg_label import SvgLabel





class IconTitleWidget(QWidget):

    def __init__(self):

        super().__init__()

        self.__initUi()



    def __initUi(self):

        iconLbl = SvgLabel()

        iconLbl.setSvgFile('ico/dark-notepad.svg')



        titleLbl = QLabel()

        titleLbl.setText('Dark Notepad')

        

        # get the point size of the titleLbl's font

        title_lbl_size = titleLbl.font().pointSize()



        # to match the iconLbl's size with titleLbl's font size (usually double size is appropriate)

        iconLbl.setFixedSize(title_lbl_size * 2, title_lbl_size * 2)



        lay = QHBoxLayout()

        lay.addWidget(iconLbl)

        lay.addWidget(titleLbl)



        self.setLayout(lay)





if __name__ == "__main__":

    import sys



    app = QApplication(sys.argv)

    ex = IconTitleWidget()

    ex.show()

    sys.exit(app.exec_())

Result

image

If iconLbl.setFixedSize(title_lbl_size * 2, title_lbl_size * 2) is not included in the code sample, size of svg icon will be adjusted to fit the size of the window.

See Also

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyqt-svg-label-0.0.12.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

pyqt_svg_label-0.0.12-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file pyqt-svg-label-0.0.12.tar.gz.

File metadata

  • Download URL: pyqt-svg-label-0.0.12.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 CPython/3.7.6

File hashes

Hashes for pyqt-svg-label-0.0.12.tar.gz
Algorithm Hash digest
SHA256 47774da34e750dd7660c71d526dcc7393e09d916a7e41997f073c5e28c20df6e
MD5 000c6bb4d00787e53a54dffeb08460e5
BLAKE2b-256 7e6692ec6e8853cbd011751d64b4b496a92c1000b5bc1fda065f98df96bb6bb5

See more details on using hashes here.

File details

Details for the file pyqt_svg_label-0.0.12-py3-none-any.whl.

File metadata

File hashes

Hashes for pyqt_svg_label-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 715e2250132e156233c26cd7dcdc22ae5eab8b19255669235aa2469b7cfadef1
MD5 ce5c748562cca2ae55bde8d193288c39
BLAKE2b-256 444e463e52ac95f6db1a4a7cb3e6cb62b1d098637d182cb84d2dab90509a6984

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page