QT QML Directory Navigation list view

Source: Internet
Author: User

function

/directories, files
/File Filtering
/recursive
/Event
/Highlight when moving forward
/Current Options
/CATALOG Switch animations
/Restrict root directory

"Download": http://download.csdn.net/detail/surfsky/8311503

"Core Code"

1Import QtQuick 2.02Import Qt.labs.folderlistmodel 2.13 4 5 /**6 qml Directory Navigation list7 /Catalog File8 /File Filtering9 /RecursiveTen /Event One /Highlight Current line A /Current Options - /CATALOG Switch animations - /Restrict root directory the  - Usage: - folderlistview{ - onitemclicked:{ + Console.debug (Json.stringify (item)); -         } +     } A  at Author: - surfsky.cnblogs.com - 2014-11 - */ - ListView { - ID:LV inwidth:300 -height:600 to  +     //----------------------------------------- -     // Public the     //----------------------------------------- *PropertyintRowheight:30//Row Height $PropertyintFontsize:20//Font SizePanax NotoginsengProperty color Hightlightcolor: "#d0d0d0"//Certain background color -PropertyvarFileFilter: ["*.QML"]//file Filter theProperty string Initfolder: './'//Initial directory +Property string RootFolder: '.. /‘//limit the root directory and no longer look up A  the     //Click events (including files and directories) +Signal itemclicked (varitem); -  $  $     //----------------------------------------- -     //Model -     //----------------------------------------- the Model:foldermodel - Folderlistmodel {Wuyi Id:foldermodel the NameFilters:lv.fileFilter - Folder:lv.initFolder WuShowdirsfirst:true -Showdotanddotdot:true About     } $  -  -     //----------------------------------------- -     //Scene Toggle Animation A     //----------------------------------------- +Propertyanimation on X{id:aniforward; from:lv.width; to:0} thePropertyanimation on X{id:aniback; from:-lv.width; to:0} -  $  the  the     //----------------------------------------- the     //Highlight Line the     //----------------------------------------- -Highlightfollowscurrentitem:false in Highlight:rectangle { the Width:lv.width; the Height:lv.rowHeight About Color:hightlightcolor the y:lv.currentitem.y; theBehavior on y {propertyanimation {properties: ' Y '; duration:300; Easing.type:Easing.OutExpo}} the         //Behavior on y {springanimation {spring:2; damping:0.1; duration:100}} +     } -  the Bayi     //----------------------------------------- the     //Agent the     //----------------------------------------- - delegate:item{ - Width:parent.width the Height:lv.rowHeight the Text { the Text:filename the Anchors.verticalCenter:parent.verticalCenter -Anchors.leftmargin:10 the font.pixelSize:lv.fontSize theX:5 the         }94 Text { theText: ">"; the Visible:fileisdir; the Anchors.verticalCenter:parent.verticalCenter98 Anchors.right:parent.right; AboutAnchors.rightmargin:10 - font.pixelSize:lv.fontSize101         }102 rectangle{103 Width:parent.width104Height:1 theColor: ' #f0f0f0 '106Y:parent.height-1107x:0108         }109  the mousearea{111 anchors.fill:parent the onclicked: {113Parent. ListView.view.currentIndex =Index the  the                 //trigger Node Click event the                 varJSON = {117 Isdir:fileisdir,118 Name:filename,119 Path:filepath, - url:fileURL.toString (),121 Basename:filebasename,122 Suffix:filesuffix,123 Size:filesize,124 modified:filemodified, the accessed:fileaccessed,126 Folderurl:getfolder (fileurl.tostring ())127                 }; - Console.debug (Json.stringify (JSON));129 lv.itemclicked (JSON); the 131                 //Directory Processing the                 if(fileisdir) {133                     //restricting the root directory134                     if(Lv.rootfolder! = "){135                         varFolderUrl = (FileURL + '/')). toLowerCase ();136                         varRootFolderURL =Qt.resolvedurl (Lv.rootfolder). toLowerCase ();137                         if(Rootfolderurl.indexof (folderurl)! =-1){138Console.log (' Limit root: ' +rootfolderurl);139                             return; $                         }141                     }142 Changefolder (Json.name, json.url);143                 }144             }145 146             //get the directory where the files are located147             functionGetFolder (FilePath)148             {149                 varn = filepath.lastindexof ('/'); Max                 varfolder = Filepath.substr (0, n+1);151                 returnfolder; the             }153 154             //change the table of contents (modify model and start the corresponding animation)155             functionChangefolder (FolderName, FolderUrl) {156                 //Foldermodel.showdotanddotdot = Folderurl!=rootfolderurl; (invalid)157Foldermodel.folder =FolderUrl;158                 if(FolderName = = ' ... ')) Aniback.start ();159                 Else if(FolderName = = '. ')) ; the                 ElseAniforward.start ();161             }162         }163     }164 165 166}

QT QML Directory Navigation list view

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: info-contact@alibabacloud.com 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.