Bon je me mets au Drag and Drop et j'ai un petit problème au niveau de ma fonction de vérification du type MIME. J'utilise l'image png en piece jointe pour mes testes. Mon problème est au niveau de la fonction event->mimeData()->hasImage() qui me renvoie toujours false.
Voici le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 #include <QtGui> #include <QtGui/QApplication> #include <QtGui/QLabel> class DragImg : public QWidget { Q_OBJECT private: QLabel* m_labelImage; public: DragImg() { this->m_labelImage = new QLabel(this); this->m_labelImage->setFixedSize(320,240); this->m_labelImage->setAcceptDrops(true); this->m_labelImage->setScaledContents(true); } protected : void dragEnterEvent(QDragEnterEvent *event) { //La verification de l'objet dragger ne fonctionne pas. if(event->mimeData()->hasImage()) { //Problème ne passe jamais ici event->acceptProposedAction(); } } void dropEvent(QDropEvent *event) { QList<QUrl> urls = event->mimeData()->urls(); if (urls.isEmpty()) return; QString fileName = urls.first().toLocalFile(); if (fileName.isEmpty()) return; this->m_labelImage->setPixmap(QPixmap(fileName)); } }; #include "main.moc" int main(int argc, char *argv[]) { QApplication a(argc, argv); DragImg w; w.show(); return a.exec(); }
Partager