【问题标题】:How to fetch file which drops in QML windows and drags from external?如何获取落在 QML 窗口中并从外部拖动的文件?
【发布时间】:2018-05-09 15:04:46
【问题描述】:

我在桌面 qml 应用程序中有一个TableView,它列出了用户将使用的文件名。文件已由用户从TreeViewQFileSystemModel 中选择。 TableView 基本上是显示文件名的一列,但在模型中存储了完整路径。我在 main.qml 中使用了ApplicationWindow

除了从TreeView 中选择文件之外,我还希望能够将文件从文件资源管理器/桌面拖放到我的应用程序中,以便在拖放后将文件名添加到模型中并显示在TreeView。这怎么可能?

【问题讨论】:

  • 您能提供一些代码供我们修复吗?
  • 我只需要存储文件名和路径

标签: qt qml


【解决方案1】:

我希望能够从文件中拖放文件 explorer/desktop 进入我的应用程序,以便在删除后 文件名得到...

将问题简化为:

How to fetch file which drops in QML windows and drags from external?

回答:DropArea

Window {
    visible: true
    width: 640
    height: 480

    DropArea {
        anchors.fill: parent
        onDropped: {
            console.log(drop.text) // file path
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-14
    • 1970-01-01
    • 2011-03-16
    • 1970-01-01
    • 2017-07-18
    • 1970-01-01
    • 2012-05-02
    • 2011-11-05
    相关资源
    最近更新 更多