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
}

 

原文链接:QML多分辨率屏幕适配_nnngo的博客-CSDN博客

posted @ 2022-05-10 11:00  Azuki_op  阅读(1004)  评论(0)    收藏  举报