qt 分辨率问题 安卓_Qt for Android dp转换

px(像素):像素是指基本原色素及其灰度的基本编码。像素是构成数码影像的基本单元,通常以像素每英寸PPI(pixels per inch)为单位来表示影像分辨率的大小。

dp(与密度无关的像素):一种基于屏幕密度的抽象单位。在每英寸160点的显示器上,1dp = 1px。

计算公式: 1dp * 像素密度 / 160 = 实际像素数

下面是一个模板用于把dp转换成实际的像素值(px)。// Units.qml

pragma Singleton

import QtQuick 2.0

/*!

\qmltype units

\brief Provides access to screen-independent units known as DPs (device-independent pixels).

This singleton provides methods for building a user interface that automatically scales based on

the screen density. Use the \l units::dp function wherever you need to specify a screen size,

and your app will automatically scale to any screen density.

Here is a short example:

\qml

import QtQuick 2.0

import Material 0.1

Rectangle {

width: units.dp(100)

height: units.dp(80)

Label {

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值