文件查看器

上节课中学习了如何加载一个网络图片,这节课接着上节课的代码来写一个图片加载程序。

首先,可以重用上节课中的图片加载的代码。新添加的东西就是,一个button,一个Text文本标签,一个FileDialog文件对话框。

具体代码如下:

import QtQuick 2.2
import QtQuick.Window 2.1
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Dialogs 1.1

Window{

    visible: true;
    width: 600;
    height: 480;

    minimumWidth: 480;
    minimumHeight: 380;

    BusyIndicator{
        id:busy;
        running: true;
        anchors.centerIn: parent;
        z:2;

    }

    Text{
        id:statusLabel;
        visible: false;
        anchors.centerIn: parent;
        z:3;
    }


    Image{
        id: imageViewer;
        asynchronous: true;
        cache: false;
        anchors.fill: parent;
        fillMode: Image.PreserveAspectFit;

        onStatusChanged: {
            if(imageViewer.states === Image.Loading){
                busy.running = true;
                statusLabel.visible = false;
            }
            else if(imageViewer.status === Image.Ready){
                busy.running = false;
            }
            else if(imageViewer.status === Image.Error){
                busy.running = false;
                statusLabel.visible = true;
                statusLabel.text = "ERROR";
            }
        }
    }

    Button{
        id:openFile;
        text:"Open";
        anchors.left: parent.left;
        anchors.leftMargin: 8;
        anchors.bottom: parent.bottom;
        anchors.bottomMargin: 8;

        style: ButtonStyle{
            background: Rectangle{
                implicitWidth: 70;
                implicitHeight: 25;
                color:control.hovered?"#c0c0c0":"#a0a0a0";
                border.width: control.pressed ? 2 : 1;
                border.color: (control.hovered || control.pressed)? "green":"#888888";
            }
        }

        onClicked: fileDialog.open();
        z:4;
    }


    Text{
        id:imagepath;
        anchors.left: openFile.right;
        anchors.leftMargin: 8;
        anchors.verticalCenter: openFile.verticalCenter;
        font.pixelSize: 18;
    }

    FileDialog{
        id: fileDialog;
        title: "Please choose a file";
        nameFilters: ["Image Files (*.jpg *.png *.gif)"];
        onAccepted: {
            imageViewer.source = fileDialog.fileUrl;
            var imageFile = new String(fileDialog.fileUrl);
            imagepath.text = imageFile.slice(8);
        }
    }


}

其中FileDialog是qml中的文件对话框,用来选择已有的文件,文件夹,支持单选多选等。
当需要多选的时候,设置以下属性就可以了。
selectMulitple:true;

universal viewer (atviewer) 是一个高级文件管理器,它的外观类似于total commander的列表,但它可预览大量文件格式,例如office文件,图片,各种网页和编码,这样使用起来就方便多了! 进入工具后,选择Options->Configure->General ->Language,更换成Chinese即可更改为中文界面! 支持的文件格式是: ·图像:全部主流的图形格式:JPG BMP ICO GIF PNG WMF TIFF PSD...,超过 40 种格式。也支持从 400 照相机的 RAW 图像。 ·多媒体:全部主流的媒体格式:AVI MPG WMV MP3 MP4 FLV MKV...,超过 170 种格式。 ·Word: MS Office Word 文件类型:DOC DOCX。 ·Excel:MS Office Excel 文件类型:XLS XLSX。 ·PDF:Adobe PDF 格式,还有 DJVU XPS CBR CBZ。 ·RTF:丰富文本格式。 ·Internet:全部由 MS Internet Explorer 支持的文件类型:HTML XML MHT... ·文本:对于未知文件类型的文本查看。可以无限大小的文件(甚至超过 4GB)。支持全部主流的文本编码。Unicode/UTF-8 查看模式可用。 ·插件:全部由 Total Commander 列表器插件 支持的文件类型。 注意:对于 Word/Excel/PDF 文件,要查看这些文件是不需要额外的软件的。根本不用安装MS Office/Adobe Reader/等。对于多媒体文件,也不需要外部编解码器。 应用程序默认是整合到 Windows 资源管理器 的上下文菜单,所以从资源管理器的任何位置调用它都没有问题:右击文件并选择 “Universal Viewer”项目。 也可以将它整合到其它流行的文件管理器内。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值