def __init__(self, name='', icon=None, *args, **kwargs): super(LabelButton, self).__init__(*args, **kwargs) self.setToolTip(name) self.setMouseTracking(True) self.setFixedSize(20, 20) if icon is not None: if isinstance(icon, (basestring, str)) and os.path.exists(icon): self.setPixmap(QtGui.QPixmap(icon)) elif isinstance(icon, QtGui.QPixmap): self.setPixmap(icon) self.setAlignment(QtCore.Qt.AlignCenter)
def set_icon(self, icon): if icon.endswith('.svg'): self.setPixmap( get_pixmap(icon).scaled( USER_ICON_SIZE, USER_ICON_SIZE, QtCore.Qt.KeepAspectRatioByExpanding, QtCore.Qt.SmoothTransformation, )) else: self.setPixmap( QtGui.QPixmap(icon).scaled( USER_ICON_SIZE, USER_ICON_SIZE, QtCore.Qt.KeepAspectRatioByExpanding, QtCore.Qt.SmoothTransformation, ))
def __init__(self, file_path, content_type='', *args, **kwargs): super(AttachmentLabel, self).__init__(*args, **kwargs) self.file_path = file_path if content_type.startswith('image'): pixmap = QtGui.QPixmap(file_path) if pixmap.width() > 0: pixmap = pixmap.scaledToWidth( min(pixmap.width(), ATTACHMENT_WIDTH), QtCore.Qt.SmoothTransformation) self.setPixmap(pixmap) else: self.setText(os.path.basename(file_path)) else: self.setText(os.path.basename(file_path)) # self.setStyleSheet(""" # QLabel{ # text-decoration:underline; # } # """) # self.setMouseTracking(True) self.setToolTip('Click to view')