Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Working example of ListView and FolderListModel? Or: what's wrong with this code?
Forum Updated to NodeBB v4.3 + New Features

Working example of ListView and FolderListModel? Or: what's wrong with this code?

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    talmage
    wrote on last edited by
    #1

    I'm trying to implement a directory browser in QML. I found and read the examples that use FolderListModel. The model seems to work. However, the ListView doesn't respond to selection. Its currentIndex never changes. The behavior is the same on my N9 and on the emulator. I am perhaps overlooking something obvious. Can one of you please tell me what's wrong with this code?

    @
    // MainPage.qml
    import QtQuick 1.1
    import com.nokia.meego 1.0
    import Qt.labs.folderlistmodel 1.0

    Page {
    tools: commonTools

    ListView {
        id: listView
        anchors.fill: parent
        clip: true
        delegate: fileDelegate
        focus: true
        highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
        model: folderModel
    
        FolderListModel {
             id: folderModel
             folder: "file:///"
             showDirs: true
             showDotAndDotDot: true
             sortField: "Name"
         }
    
         Component {
             id: fileDelegate
             Text {
                 font.family: "Nokia Pure Text"
                 font.pixelSize: 24
                 text: fileName
             }
         }
    
         onCurrentIndexChanged: {
             console.debug("listView currentIndex:", currentIndex)
         }
    }
    

    }
    @

    @
    // main.qml
    import QtQuick 1.1
    import com.nokia.meego 1.0

    PageStackWindow {
    id: appWindow

    initialPage: mainPage
    
    MainPage {
        id: mainPage
    }
    
    ToolBarLayout {
        id: commonTools
        visible: true
        ToolIcon {
            platformIconId: "toolbar-view-menu"
            anchors.right: (parent === undefined) ? undefined : parent.right
            onClicked: (myMenu.status == DialogStatus.Closed) ? myMenu.open() : myMenu.close()
        }
    }
    
    Menu {
        id: myMenu
        visualParent: pageStack
        MenuLayout {
            MenuItem { text: qsTr("Quit"); onClicked: Qt.quit() }
        }
    }
    

    }
    @

    1 Reply Last reply
    0
    • I Offline
      I Offline
      ixSci
      wrote on last edited by
      #2

      There is no built-in selection functional in ListView so you should implement it yourself. Just add MouseArea to your delegate and change ListView currentItem to index of the delegate in the onClicked handler.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved