How to implement a filedialog on an Ubuntu phone

Source: Internet
Author: User
Tags i18n

Some time ago, a developer asked me if I could use qtquick.dialogs in my Ubuntu phone to implement FileDialog. At present, there is no QT this library on the mobile phone implementation. The main reason is that it does not use the unit grid layout, so it appears very small on the real phone. So how can we achieve the same function?

Let's look at the API Dialog provided by our Ubuntu Qt first. Here we have a control that provides a dialog. We can follow the example above to write the routines we need. In addition, we also need to use another apifolderlistmodel. Through this API we can get all the files we need for the directory of files:

By understanding and using these two APIs, we can quickly make the following test applications:

Import QtQuick 2.0import ubuntu.components 1.1import Ubuntu.Components.Popups 0.1import Qt.labs.folderlistmodel 2.1/*! \brief MainView with a Label and Button Elements.*/mainview {//ObjectName for functional testing purposes (autopilot -QT5) ObjectName: "MainView"//note! ApplicationName needs to match the "name" field of the click Manifest ApplicationName: "Filedialog.ubuntu"/* Th Is property enables the application to change orientation when the device is rotated.    The default is False.    *///automaticorientation:true//Removes the old toolbar and enables new features of the new header.        Usedeprecatedtoolbar:false ( page { ("simple") button {id:launcher ("Open") (+) onclicked:p (dialog, NULL)} Component {Id:dialog dialog {Id:diAlogue title: "FileList Dialog" text: "Show the Files" ListView { Id:listview width:parent.width height:200 Folderlistmo                                          del {Id:foldermodel namefilters: ["*.QML"]                            } Component {id:filedelegate Text {                                Id:text Text:filename Mousearea { Anchors.fill:parent onclicked: {Conso                                    Le.log ("It is clicked");                                Listview.currentindex = index;  }}}}//Define a highlight with Customized Movement BetWeen items. Component {id:highlightbar Rectangle {width:f Iledelegate.width;                            Height:50 color: "Red" Y:LISTVIEW.CURRENTITEM.Y;                    Behavior on y {springanimation {spring:2; damping:0.1}}}}                    Focus:true Model:foldermodel Delegate:filedelegate Highlight:highlightbar} Row {Id:row Width:pa Rent.width (1) Button {width:parent.width/                    2 text: "Cancel" OnClicked:PopupUtils.close (Dialogue)} Button {WIDTH:PARENT.WIDTH/2 TExt: "Confirm" onclicked: {                            Console.log ("Caller:" + Dialogue.caller);                            Console.log ("Currentindex:" + listview.currentindex);                            Console.log (Foldermodel.get (Listview.currentindex, "fileName"));                            Launcher.update (); Popuputils.close (Dialogue)}}}}}}

To run our application, we can see:

It must be noted here that Folderlistmodel does not have access to any directory of the system. We can refer to the article "Ubuntu OS Application Runtime enviroment" to get what directories are accessible. For accessing files owned by another application, we can access them by using Contenthub.

Source code for all applications in: Git clone

How to implement a filedialog on an Ubuntu phone

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.