Important: Please read the Qt Code of Conduct -

How to do with resolution adaptation?

  • For better layout, I often use plain number to layout, such aslayout->setSpacing(20),font.setPixelSize(12);,etc...(I know setPointSize() can replace setPixelSize() to get better adaptation, here is just a example, ignore it.)

    So, if you use plain numbers to layout your app interface, it will lost it's adaptation.

    I think it deeply for some time, finally find a way: by using resolution proportion.

    for example,

    QSize currentResolution = getResolution();
    double resolutionProportion = currentResolution.width() / 1920.0; // 1920 is the resolution's width of your pc on which develop this app
    layout->setSpacing(20 * resolutionProportion );

    Is this a good solution? If not, could you tell me the better or best solution?

    Thanks a lot.

  • Lifetime Qt Champion

    You are using an int for resolutionProportion so i fear it will be truncated and zero
    for most cases.
    To have effect, i think you need something like

    double resolutionProportion = (double )currentResolution.width() / 1920.0;
    layout->setSpacing( ceil(20 * resolutionProportion ));
    (or floor or round )

    Other than that, i think the idea is fine enough.

  • @mrjj Yes, yes....I wrote it wrong, sorry, thanks for your response.

Log in to reply