日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 芯聞號(hào) > 充電吧
[導(dǎo)讀]網(wǎng)上大多數(shù)都是那一套公式,不適合拉伸布局,假如有一張圖片或者一個(gè)被固定了大小的控件或圖片,那么可能會(huì)失真,下面是自己實(shí)現(xiàn)的自適應(yīng),非常好用的說。而且網(wǎng)上大多數(shù)Qt quick開發(fā)群心高氣傲,根本不要人

網(wǎng)上大多數(shù)都是那一套公式,不適合拉伸布局,假如有一張圖片或者一個(gè)被固定了大小的控件或圖片,那么可能會(huì)失真,下面是自己實(shí)現(xiàn)的自適應(yīng),非常好用的說。而且網(wǎng)上大多數(shù)Qt quick開發(fā)群心高氣傲,根本不要人加入。很多東西可以自己研究的,樂于分享的人太少 一句話,沒圖說個(gè)JB,開干!

下面寫一個(gè)Col容器,寬度是固定的,這種情況下,在各種移動(dòng)平臺(tái)下會(huì)差別很大,不過根據(jù)我的算法就解決了,320*480是我寫代碼設(shè)計(jì)界面時(shí)用的界面size,在安卓上,size會(huì)根據(jù)系統(tǒng)的分辨率而不同,因此在代碼中把320*480作為模板,換了系統(tǒng)會(huì)計(jì)算比例

import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.3
//import QtQuick.Extras 1.4
import "./UI.js"  as Mui
ApplicationWindow {

    id:root;
    width: 320;
    height: 480;
    visible: true;
     //獲取最終dpi
      //     targetDensitydpi = uiWidth / deviceWidth * devicePixelRatio * 160;
//Screen.devicePixelRatio



    Component.onCompleted: {

    }
    property real pixelDensity: 4.46 
    property real multiplierH: root.height/480 //default multiplier, but can be changed by user
     property real multiplierW: root.width/320 //default multiplier, but can be changed by user
    function dpH(numbers) {

        return Math.round(numbers*((pixelDensity*25.4)/160)*multiplierH);
    }
    function dpW(numbers) {

        return Math.round(numbers*((pixelDensity*25.4)/160)*multiplierW);
    }


    Label{

           anchors.centerIn: parent
           id:label;
           text: "..";
    }

    //固定寬高自適應(yīng)屏幕
        Column{

            spacing: dpH(1);
            width: dpW(440);
            Repeater{
                model: 17;
                delegate:Rectangle{
                    width: parent.width;
                    height:dpH(40);


                    color: "#2a9f8d"
                    Text {

                        color: "white";
                        font.bold: true;
                        font.pointSize:14;
                        text:index+ ",標(biāo)題dp3+"+parent.height+","+multiplierH+","+multiplierW+",";
                        anchors.centerIn: parent;
                    }
                }
            }

        }




}

注意,設(shè)計(jì)中我把界面右邊留了空白 最后一行為第16列并且顯示不完全.這樣容易看出差異:
在電腦上的效果,此時(shí)程序的窗口大小是320*480

在電腦上手動(dòng)調(diào)整界面大小的效果,此時(shí)程序的窗口大小未知

在安卓模擬器上的效果,分辨率是1280*720 192dpi

來一段顯示圖片的代碼,好用不失真

    Column{
        spacing: dpH(1);
        width: parent.width;
        Repeater{
            model: 5;
            delegate: BorderImage {
                id: name
                source: "astop.png"
                width: dpW(72); height: width
                border.left: dpW(1); border.top: dpH(1)
                border.right: dpW(1); border.bottom: dpH(1)
            }
        }
    }


本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉