Results 1 to 5 of 5

Thread: QML FolderListModel how to set nameFilters for directory with Script

  1. #1
    Join Date
    Feb 2017
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QML FolderListModel how to set nameFilters for directory with Script

    I want to create a filter to display the directories. The script works well with files, but does not work with directories. What am I doing wrong?
    Qt Code:
    1. function updateFilter()
    2. {
    3. var text = searchField.text
    4. var filter = "*"
    5. for(var i = 0; i<text.length; i++)
    6. filter+= text[i]
    7. filter+="*"
    8. print(filter)
    9. folderDirModel.nameFilters = [filter]
    10. }
    11.  
    12. TextField{
    13. id: searchField
    14. width: parent.width
    15. font.pointSize: 16
    16. padding: 0
    17. visible: true
    18. onTextChanged: updateFilter()
    19. }
    20. ListView {
    21. id: dirView
    22. anchors.topMargin: 50
    23. anchors.leftMargin: 75
    24. antialiasing: false
    25. scale: 1
    26. spacing: 1
    27. anchors.fill: parent
    28. clip: true
    29. model: folderDirModel
    30. delegate: folderDeligate
    31.  
    32. FolderListModel {
    33. id: folderDirModel
    34. objectName: "folderDirModel"
    35. sortField: FolderListModel.Name
    36. showDirs: true
    37. showFiles: false
    38. folder: "file:///Users/public/Directory/"
    39. nameFilters: ["*.*"]
    40. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QML FolderListModel how to set nameFilters for directory with Script

    Can you modify the example to be actually runnable, e.g. with qmlscene?

    Your function looks curious, especially the loop. Why not concatenate the whole string instead of character by character?
    Qt Code:
    1. var filter = "*" + text + "*"
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Feb 2017
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QML FolderListModel how to set nameFilters for directory with Script

    Well, here's the scheme. var filter = "*" + text + "*" has not given result...

    Qt Code:
    1. import QtQuick 2.5
    2. import QtQuick.Window 2.0
    3. import QtQuick.Controls 2.0
    4. import QtQuick.Dialogs 1.2
    5. import Qt.labs.folderlistmodel 2.1
    6.  
    7. ApplicationWindow
    8. {
    9. id: app
    10. width: 800
    11. height: 600
    12.  
    13. property var directoryModel: folderDirModel
    14. property var directoryListView: karDirView
    15.  
    16. TextField{
    17. id: searchField
    18. x: 0
    19. width: parent.width
    20. font.pointSize: 16
    21. padding: 0
    22. visible: true
    23. onTextChanged: updateFilter()
    24. }
    25.  
    26. ListView {
    27.  
    28. id: karDirView
    29. anchors.topMargin: 50
    30. anchors.leftMargin: 75
    31. antialiasing: false
    32. scale: 1
    33. spacing: 1
    34. anchors.fill: parent
    35. clip: true
    36. model: folderDirModel
    37. delegate: folderDeligate
    38.  
    39. FolderListModel {
    40. id: folderDirModel
    41. objectName: "folderDirModel"
    42. sortField: FolderListModel.Name
    43. showDirs: true
    44. showFiles: false
    45. folder: "file:///Users/public/Directory/"
    46. nameFilters: ["*.*"]
    47.  
    48.  
    49. }
    50.  
    51.  
    52. Component{
    53. id: folderDeligate
    54. Row {
    55. Rectangle {
    56. id: directoryRectangle
    57. width: 400
    58. height: 50
    59. gradient: Gradient {
    60. GradientStop { position: 0.0; color: "#c8892c" }
    61. GradientStop { position: 1.0; color: "#ebb07c" }
    62. }
    63. Text {
    64. text: fileName
    65. anchors.leftMargin: 10
    66. anchors.verticalCenter: parent.verticalCenter
    67. color: "#192437"
    68. font.pointSize: 16
    69. }
    70.  
    71. }
    72. }
    73.  
    74. }
    75.  
    76. }
    77.  
    78.  
    79. function updateFilter()
    80. {
    81. var text = searchField.text
    82. var filter = "*" + text + "*"
    83. //for(var i = 0; i<text.length; i++)
    84. // filter+= text[i]
    85. // filter+="*"
    86. print(filter)
    87. folderDirModel.nameFilters = [filter]
    88. }
    89. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QML FolderListModel how to set nameFilters for directory with Script

    Thanks for the runnable example.

    Meanwhile I found this in the documentation for the FolderListModel:
    Note: Directories are not excluded by filters.
    and
    Note that the nameFilters are not applied to directories.
    Cheers,
    _

  5. #5
    Join Date
    Feb 2017
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QML FolderListModel how to set nameFilters for directory with Script

    Bad news. Well I will look for another solution. Thank you

Similar Threads

  1. QML FolderListModel & StackView
    By scgrant327 in forum Qt Quick
    Replies: 1
    Last Post: 18th May 2016, 00:03
  2. How to fetch files one by one from FolderListModel in QML?
    By TheIndependentAquarius in forum Qt Quick
    Replies: 2
    Last Post: 7th March 2016, 06:45
  3. FolderListModel custom property
    By WeX.tmpvar in forum Qt Quick
    Replies: 0
    Last Post: 18th February 2012, 07:57
  4. Replies: 2
    Last Post: 7th September 2010, 09:38
  5. nsis script question: directory tree
    By vonCZ in forum General Programming
    Replies: 3
    Last Post: 28th November 2008, 01:22

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.