查看完整版本: [-- QUICK 内width,height是什么单位? --]

QTCN开发网 -> Qt QML开发 -> QUICK 内width,height是什么单位? [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

lovexin109 2017-09-25 16:51

QUICK 内width,height是什么单位?

  1. 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??

never_forget 2017-09-26 08:31
应该是 像素 吧

lovexin109 2017-09-26 17:11
never_forget:应该是 像素 吧 (2017-09-26 08:31)

但是在手机上运行,label1,label2的text运行显示360和616,这样可能就不是像素吧



never_forget 2017-09-27 08:49
管他是啥,能用

就行

lemonzll 2017-09-27 15:41
你main函数开头是不是加的有这句,QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);如果启用的有这个,quick里面的像素就相当于是dp,如果没有启用,就是按实际的像素。这是Qt 5.6开始才引入的。启用以后尺寸信息都是实际的大小除以或乘以屏幕的像素比,屏幕的像素比可以用qApp->devicePixelRatio()查看下,你手机应该是3,比如定义一个150x150的矩形,实际上是450x450了


查看完整版本: [-- QUICK 内width,height是什么单位? --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled