首页| 论坛| 消息

标题:QUICK 内width,height是什么单位?
作者:lovexin109
日期:2017-09-25 16:51
内容:

ApplicationWindow {
id:mainwindow
visible: true
width: 1080
height: 1740
title: qsTr("Hello World")
Rectangle {
id: mainrec
anchors.fill: parent
Label {
id:label1
text:parent.width
anchors.centerIn: parent
}
Label{
id:label2
text:parent.height
anchors.top: label1.bottom
anchors.verticalCenter: parent.verticalCenter
}
}

}代码如上:
手机1080X1920,运行结果是360X616,(去掉手机最上面那一栏高度刚好是1848)基本上是3的系数,想问下width和height的单位是什么,为什么会得出360和616?难道是dp??


#1 [never_forget 09-26 08:31]
应该是 像素 吧
#2 回 never_forget 的帖子 [lovexin109 09-26 17:11]
never_forget:应该是 像素 吧 (2017-09-26 08:31)
但是在手机上运行,label1,label2的text运行显示360和616,这样可能就不是像素吧
#3 [never_forget 09-27 08:49]
管他是啥,能用
就行
#4 [lemonzll 09-27 15:41]
你main函数开头是不是加的有这句,QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);如果启用的有这个,quick里面的像素就相当于是dp,如果没有启用,就是按实际的像素。这是Qt 5.6开始才引入的。启用以后尺寸信息都是实际的大小除以或乘以屏幕的像素比,屏幕的像素比可以用qApp->devicePixelRatio()查看下,你手机应该是3,比如定义一个150x150的矩形,实际上是450x450了

回复 发表
主题 版块