Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QSize ratio..



  • When you change from QSize (A, B) to QSize (A + x, B + y), how do you get x, y to get the same percentage of results as the first A and B ratios?


  • Moderators

    @Pada_ said in QSize ratio..:

    When you change from QSize (A, B) to QSize (A + x, B + y), how do you get x, y to get the same percentage of results as the first A and B ratios?

    Can you give an example, using actual numbers that you want? Your question is unclear.

    Anyway, see if QSize::scale() or QSize::scaled() fits your needs.


  • Lifetime Qt Champion

    @Pada_ I would say to keep same ratio you need to do: x = ratio * y (because ratio = x / y)
    So, if you want to increase the height by 4 pixels and ratio is 1.5 (3/2) then you need to increase x by 1.5 * 4 = 6
    For example:
    A = 30
    B = 20
    ratio = 3/2 = 1.5
    y = 4
    => x = 1.5 * 4 = 6
    Anew = 36
    Bnew = 24
    36 / 24 = 1.5


Log in to reply