(size: QSizeF, constraint: QSizeF, mode=Qt.KeepAspectRatio)
return size
Return size scaled to fit in the constrains using the aspect mode `mode`.

    If  width or height of constraint are negative they are ignored,
    ie. the result is not constrained in that dimension.
Return size scaled to fit in the constrains using the aspect mode `mode`.
Return size scaled to fit in the constrains using the aspect mode mode .
def scaled(size: QSizeF, constraint: QSizeF, mode=Qt.KeepAspectRatio) -> QSizeF:
    """
    Return size scaled to fit in the constrains using the aspect mode `mode`.

    If  width or height of constraint are negative they are ignored,
    ie. the result is not constrained in that dimension.
    """
    size, constraint = QSizeF(size), QSizeF(constraint)
    if size.isEmpty():
        return size
    if constraint.width() < 0 and constraint.height() < 0:
        return size
    if mode == Qt.IgnoreAspectRatio:
        if constraint.width() >= 0:
            size.setWidth(constraint.width())
        if constraint.height() >= 0:
            size.setHeight(constraint.height())
    elif mode == Qt.KeepAspectRatio:
        if constraint.width() < 0:
            constraint.setWidth(QWIDGETSIZE_MAX)
        if constraint.height() < 0:
            constraint.setHeight(QWIDGETSIZE_MAX)
        size.scale(constraint, mode)
    elif mode == Qt.KeepAspectRatioByExpanding:
        if constraint.width() < 0:
            constraint.setWidth(0)
        if constraint.height() < 0:
            constraint.setHeight(0)
        size.scale(constraint, mode)
    return size
def scaled ( size : QSizeF , constraint : QSizeF , mode = Qt . KeepAspectRatio ) -> QSizeF : size , constraint = QSizeF ( size ) , QSizeF ( constraint ) if size . isEmpty ( ) : return size if constraint . width ( ) < 0 and constraint . height ( ) < 0 : return size if mode == Qt . IgnoreAspectRatio : if constraint . width ( ) >= 0 : size . setWidth ( constraint . width ( ) ) if constraint . height ( ) >= 0 : size . setHeight ( constraint . height ( ) ) elif mode == Qt . KeepAspectRatio : if constraint . width ( ) < 0 : constraint . setWidth ( QWIDGETSIZE_MAX ) if constraint . height ( ) < 0 : constraint . setHeight ( QWIDGETSIZE_MAX ) size . scale ( constraint , mode ) elif mode == Qt . KeepAspectRatioByExpanding : if constraint . width ( ) < 0 : constraint . setWidth ( 0 ) if constraint . height ( ) < 0 : constraint . setHeight ( 0 ) size . scale ( constraint , mode ) return size