QML多分辨率屏幕适配

 property int defaultW  : 520
    property int defaultH   :   900



width: Qt.platform.os == "windows" || Qt.platform.os == "osx" ? defaultW : Screen.desktopAvailableWidth
    height: Qt.platform.os == "windows" || Qt.platform.os == "osx" ? defaultH : Screen.desktopAvailableHeight


/*************************************************************************************
        计算宽高比例
    *************************************************************************************/
    function dpW( value )
    {
        var temp
        if(Qt.platform.os == "windows" || Qt.platform.os == "osx" )
        {
            temp = (mainwindow.width / defaultW) * value
        }else
        {
            temp = Screen.primaryOrientation === 1 ? (mainwindow.width / defaultW) * value : (mainwindow.height / defaultW) * value
        }
        return temp
    }

    function dpH( value )
    {
        var temp
        if(Qt.platform.os == "windows" || Qt.platform.os == "osx")
        {
            temp =  (mainwindow.height / defaultH) * value
        }else
        {
            temp = Screen.primaryOrientation === 1 ?  (mainwindow.height / defaultH) * value : (mainwindow.width / defaultH) * value
        }
        return temp
    }

 

你可能感兴趣的:(Qt)