Skip to content

Commit

Permalink
添加 ImageLabel 设置任意大小的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyiYo committed Oct 20, 2024
1 parent 0910794 commit f0eea4d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
41 changes: 41 additions & 0 deletions examples/text/image_label/demo.py
Original file line number Diff line number Diff line change
@@ -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_()
Binary file added examples/text/image_label/resource/Gyro.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/text/image_label/resource/boqi.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions qfluentwidgets/components/widgets/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit f0eea4d

Please sign in to comment.