Created
August 25, 2022 13:15
-
-
Save quevon24/47aa1de812a3d0ff83fcc13720b80cd7 to your computer and use it in GitHub Desktop.
PyQt6 icon label widget, requires QtAwesome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
PyQt6 icon label | |
Requires PyQt6 and QtAwesome | |
Usage examples: | |
Basic usage: | |
layout = QVBoxLayout() | |
test_label = IconLabel("ph.files-light", "File List:") | |
layout.addWidget(test_label) | |
Define icon size, horizontal spacing: | |
layout = QVBoxLayout() | |
test_label = IconLabel("ph.files-light", "File List:", icon_size=QSize(16,16), horizontal_spacing=0) | |
layout.addWidget(test_label) | |
""" | |
from PyQt6.QtCore import QSize | |
from PyQt6.QtWidgets import QWidget, QHBoxLayout, QLabel | |
import qtawesome as qta | |
class IconLabel(QWidget): | |
def __init__(self, qta_id, text, final_stretch=True, icon_size=QSize(32, 32), | |
horizontal_spacing=2): | |
super(QWidget, self).__init__() | |
layout = QHBoxLayout() | |
layout.setContentsMargins(0, 0, 0, 0) | |
self.setLayout(layout) | |
icon = QLabel() | |
icon.setPixmap(qta.icon(qta_id).pixmap(icon_size)) | |
layout.addWidget(icon) | |
layout.addSpacing(horizontal_spacing) | |
layout.addWidget(QLabel(text)) | |
if final_stretch: | |
layout.addStretch() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment