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.