diff --git a/examples/text/image_label/demo.py b/examples/text/image_label/demo.py new file mode 100644 index 000000000..e4d85f7a1 --- /dev/null +++ b/examples/text/image_label/demo.py @@ -0,0 +1,41 @@ +# coding:utf-8 +import sys + +from PyQt5.QtCore import Qt +from PyQt5.QtGui import QIcon +from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout + +from qfluentwidgets import ImageLabel + + +class Demo(QWidget): + + def __init__(self): + super().__init__() + self.imageLabel = ImageLabel("resource/Gyro.jpg") + self.gifLabel = ImageLabel("resource/boqi.gif") + self.vBoxLayout = QVBoxLayout(self) + + # change image + # self.imageLabel.setImage("resource/boqi.gif") + + self.imageLabel.scaledToHeight(300) + self.gifLabel.scaledToHeight(300) + + self.imageLabel.setBorderRadius(0, 30, 30, 0) + self.gifLabel.setBorderRadius(10, 10, 10, 10) + + self.vBoxLayout.addWidget(self.imageLabel) + self.vBoxLayout.addWidget(self.gifLabel) + + +if __name__ == '__main__': + # enable dpi scale + QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) + QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) + QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) + + app = QApplication(sys.argv) + w = Demo() + w.show() + app.exec_() \ No newline at end of file diff --git a/examples/text/image_label/resource/Gyro.jpg b/examples/text/image_label/resource/Gyro.jpg new file mode 100644 index 000000000..d2ed097ee Binary files /dev/null and b/examples/text/image_label/resource/Gyro.jpg differ diff --git a/examples/text/image_label/resource/boqi.gif b/examples/text/image_label/resource/boqi.gif new file mode 100644 index 000000000..2656b39a3 Binary files /dev/null and b/examples/text/image_label/resource/boqi.gif differ diff --git a/qfluentwidgets/components/widgets/label.py b/qfluentwidgets/components/widgets/label.py index ddb190a4f..49d0cfa82 100644 --- a/qfluentwidgets/components/widgets/label.py +++ b/qfluentwidgets/components/widgets/label.py @@ -318,6 +318,15 @@ def scaledToHeight(self, height: int): if self.movie(): self.movie().setScaledSize(QSize(w, height)) + def setScaledSize(self, size: QSize): + if self.isNull(): + return + + self.setFixedSize(size) + + if self.movie(): + self.movie().setScaledSize(size) + def isNull(self): return self.image.isNull()