QML fit screen on all resolutions

前端 未结 3 1699
无人共我
无人共我 2021-02-07 12:13

Hi all I have problem with my QML code. I made mistake and I went to put certain size to elements and now I have problem when putting app on other devices. I will paste you my

3条回答
  •  轮回少年
    2021-02-07 12:49

    It's unfortunately tricky to get perfect, as it's likely that as the screen size shrinks you might actually want the buttons to be bigger and to drop content from the screen to ensure the user can access and read everything ok.

    But the general approach is actually to set a scale factor in the C++ side:

    ctxt->setContextProperty("scale", /* put calculated scale factor here */);
    

    And then on the QML side, use that everyone to scale all the objects:

    Rectangle {
    
        id:window
        width: 602 * scale
        height: 1000 * scale
    

    That way you can adjust the scale variable to change everything's size. Having said that, many people end up with different QML files depending on the platform size though.

提交回复
热议问题