Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //main.cpp
- #include <QGuiApplication>
- #include <QtQml>
- #include <drop.hpp>
- using namespace Qt;
- int main(int argc, char *argv[])
- {
- QGuiApplication app(argc, argv);
- qmlRegisterType<Drop>("areaOfDrop", 1, 0, "AreaOfDrop");
- QQmlApplicationEngine engine;
- engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
- return app.exec();
- }
- //drop.hpp
- #pragma once
- #include <QtWidgets>
- class Drop :public QLabel {
- Q_OBJECT
- Q_PROPERTY(QString style WRITE setStyle)
- public:
- Drop(Drop* pp = nullptr);
- void setStyle(QString data);
- protected:
- virtual void dragEnterEvent(QDragEnterEvent* pe) override;
- virtual void dropEvent(QDropEvent* pe) override;
- };
- //drop.cpp
- #include "drop.hpp"
- using namespace Qt;
- Drop::Drop(Drop* pp) :QLabel(pp)
- {
- setAcceptDrops(true);
- }
- void Drop::setStyle(QString data) {
- this->setStyleSheet(data);
- }
- void Drop::dragEnterEvent(QDragEnterEvent* pe) {
- if(pe->mimeData()->hasFormat("text/*")) {
- pe->acceptProposedAction();
- }
- }
- void Drop::dropEvent(QDropEvent* pe) {
- QList<QUrl> urlList = pe->mimeData()->urls();
- foreach(QUrl url, urlList) {
- QFile file(url.toString());
- QByteArray data = file.readAll();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement