我注意到Qt5中有一個新的DropArea組件。我試圖從Finder中拖動一個文件(Mac),但只有onEntered方法被調用。QML DropArea接受外部阻力
import QtQuick 2.0
Rectangle {
id: background;
color: "white";
width: 300;
height: 300;
DropArea {
id: dropArea;
anchors.fill: parent;
onEntered: {
background.color = "gray";
drag.accept (Qt.CopyAction);
console.log("onEntered");
}
onDropped: {
console.log ("onDropped");
}
onExited: {
bckground.color = "white";
console.log ("onExited");
}
}
}
這裏是窗口創建代碼:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QQuickView qmlView;
qmlView.setGeometry(0, 200, 600, 400);
qmlView.setResizeMode (QQuickView::SizeRootObjectToView);
qmlView.setSource(QUrl::fromLocalFile("/Users/ivann/Projects/QtGuiTestApp/testView.qml"));
qmlView.show();
return a.exec();
}
我缺少的東西?
qt版本是5.0.0 beta 1 –
也許它可以幫助你[鏈接](http://lists.qt.nokia.com/pipermail/qt-qml/2011-December/003335.html) –
@aleks_misyuk謝謝。不幸的是,這是關於本地拖放。 –