调整手机屏幕的应用程序分辨率

Adjust application resolution for mobile screens

您好,我已尝试针对移动屏幕调整我的 QML 应用程序。我的主屏幕由 TabView 中的 Tab 组成:

import QtQuick 2.5
import QtQuick.Window 2.1
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.4
TabView {
    Tab{
      id: Tab1 
      component: Qt.createComponent("qrc:///LoginScreen.qml")}
    Tab{
      id: Tab1
      component: Qt.createComponent("qrc:///AfterLogged.qml")}}`

LoginScreen.qml中我有Buttons、Labels、TextFields来获取数据:

import QtQuick 2.5
import QtQuick.Window 2.1
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.4
Item { 
  Label {
    id: ipAddressLabel
    text: qsTr("Address IP:")
  TextField {
    id: ipTextField
    placeholderText: qsTr("Insert IP address")
  Button {
    id: loginBtn
    onClicked: {
     connectToApp(ipTextField.text)}}
    }

如何根据特定的移动屏幕调整我的应用程序屏幕大小resolution/density?

看看 Screen 类型。

它包含您屏幕的当前 heightwidth,可以分配给您的 LoginScreen.qml widthheight 属性:

Item {
    width: Screen.width
    height: Screen.height

    //[...]
}

请注意,如果您想使用带边距的 anchors,您必须更深入地计算并正确计算边距。