QML ranges from 1 to 2, and qml ranges from 1 to 2.

Source: Internet
Author: User

QML ranges from 1 to 2, and qml ranges from 1 to 2.

As the project goes deeper, it needs to be transplanted to Android. The problem is that QML Android is compatible!

Fortunately, the PC-side program is similar to the cell phone screen width ratio. Although the unit pixels and sizes are different, you can use proportional scaling to implement universal code for components PC and Android.

Step 1: define a global Conversion Function (300,500 is the size of your PC)

 1 property var x_scale:mainWindow.width/300 2 property var y_scale:mainWindow.height/500 3  4 function get_x(x) 5 { 6     return x*x_scale; 7 } 8 function get_y(y) 9 {10     return y*y_scale;11 }

Step 2: Use the preceding Conversion Function to calculate the new values of all the related dimensions.

1 Text {2         id:nameText3         x:get_x(8)4         y:get_y(11)5         width:get_x(80)6         horizontalAlignment:Text.AlignRight7         color: "#000000"8         text: ""9     }

Step 3: For some controls, Android and PC have different forms of presentation. You need to determine the platform and define additional settings. Platform code judgment

Function is_android () {return (Qt. platform. OS = "android");} // call method Image {id: imageLogo y: get_y (58) width: get_x (167) height: get_y (70) anchors. horizontalCenterOffset: is_android ()? Get_x (-8): get_x (-4) anchors. horizontalCenter: parent. horizontalCenter source: "logo.png "}

Finally, we recommend that you use pixelSize to define the adaptation of the font size. You also need a conversion function to calculate the new size, so that it can be consistent with other controls.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.