Advertisement
PlotnikovPhilipp

Untitled

May 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. //main.cpp
  2.  
  3.  
  4.  
  5. #include <QGuiApplication>
  6. #include <QtQml>
  7. #include <drop.hpp>
  8.  
  9. using namespace Qt;
  10.  
  11. int main(int argc, char *argv[])
  12. {
  13. QGuiApplication app(argc, argv);
  14. qmlRegisterType<Drop>("areaOfDrop", 1, 0, "AreaOfDrop");
  15. QQmlApplicationEngine engine;
  16. engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
  17. return app.exec();
  18. }
  19.  
  20. //drop.hpp
  21.  
  22.  
  23.  
  24.  
  25. #pragma once
  26.  
  27. #include <QtWidgets>
  28.  
  29. class Drop :public QLabel {
  30. Q_OBJECT
  31. Q_PROPERTY(QString style WRITE setStyle)
  32. public:
  33. Drop(Drop* pp = nullptr);
  34. void setStyle(QString data);
  35. protected:
  36. virtual void dragEnterEvent(QDragEnterEvent* pe) override;
  37. virtual void dropEvent(QDropEvent* pe) override;
  38. };
  39.  
  40. //drop.cpp
  41.  
  42.  
  43.  
  44. #include "drop.hpp"
  45.  
  46. using namespace Qt;
  47.  
  48. Drop::Drop(Drop* pp) :QLabel(pp)
  49. {
  50. setAcceptDrops(true);
  51. }
  52.  
  53. void Drop::setStyle(QString data) {
  54. this->setStyleSheet(data);
  55. }
  56.  
  57. void Drop::dragEnterEvent(QDragEnterEvent* pe) {
  58. if(pe->mimeData()->hasFormat("text/*")) {
  59. pe->acceptProposedAction();
  60. }
  61. }
  62.  
  63. void Drop::dropEvent(QDropEvent* pe) {
  64. QList<QUrl> urlList = pe->mimeData()->urls();
  65. foreach(QUrl url, urlList) {
  66. QFile file(url.toString());
  67. QByteArray data = file.readAll();
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement