Hello everyone,

I have made a chessgame, now I wanted to create a GUI for it, using model-view.
Every time I click a chesspiece (to dragn and drop) I want to store the original location of the DnDPixmap into 2 variables, so I still have the original location when I drop my chesspiece.
Then I can use those x and y values to see if the move is possible using my normal c++code.
The problem is, when I drag the adress of the DnDPixmap I hold seems to change, at least that's what my messageboxes are saying.

Qt Code:
  1. DnDPixmap::DnDPixmap(const QPixmap &pixmap, uitzicht* a)
  2. {
  3. // Make sure we allow drops.
  4. setAcceptDrops(true);
  5. connect(this, SIGNAL(moveMade( int, int, int, int)), a, SLOT(myslot( int, int, int, int)));
  6.  
  7. }
  8.  
  9.  
  10. void DnDPixmap::mousePressEvent(QGraphicsSceneMouseEvent* event)
  11. {
  12.  
  13.  
  14. // We need to overload this method to make sure that
  15. // nothing happens on a mouse press (e.g. select, move).
  16. //
  17. // This causes e.g. setFlag(QGraphicsItem::ItemIsMovable)
  18. // to stop working, since flags modifies the mousePressEvent
  19. // method of the base class, which is not called anymore now.
  20. if (event->button() != Qt::LeftButton) {
  21. event->ignore();
  22. return;
  23. }
  24. }
  25.  
  26. void DnDPixmap::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
  27. {
  28. // Check if move distance is above standard treshold.
  29. if (QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton))
  30. .length() < QApplication::startDragDistance())
  31. {
  32. return;
  33. }
  34.  
  35.  
  36.  
  37.  
  38. this->oudeX = event->lastScenePos().rx()/50;
  39. this->oudeY = event->lastScenePos().ry()/50;
  40.  
  41. // Create a drag object with mimetype data.
  42. QDrag *drag = new QDrag(event->widget());
  43. QMimeData *mime = new QMimeData;
  44. drag->setMimeData(mime);
  45.  
  46. // Add text to the QMimeData object.
  47. // QVariant is like a union, it can
  48. // contain different kinds of types.
  49. mime->setImageData(QVariant(pixmap()));
  50.  
  51. // Show a scaled icon of the current image next to
  52. // the cursor when dragging. Scale it to be 30px wide.
  53. drag->setPixmap(pixmap().scaledToWidth(30, Qt::FastTransformation));
  54. // Set the cursor's tip (or hot spot) to point to
  55. // the center of the pixmap's bottom edge.
  56. drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height()));
  57.  
  58. QLabel* label = new QLabel;
  59. QString p=QString::number((int)this,16);
  60.  
  61. label->setText("pointerINMOUSEMOVEEVENT="+p);
  62. label->show();
  63.  
  64.  
  65. // Start the drag operation.
  66. drag->exec();
  67. }
  68.  
  69. void DnDPixmap::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
  70. {
  71. // Is the data correct (an image that can be loaded)?
  72. bool imageLoaded = false;
  73. const QMimeData *mime = event->mimeData();
  74. // Are there URLs present?
  75. if (mime->hasUrls())
  76. {
  77. // Fetch the list of URLs dragged over.
  78. const QList<QUrl> &urls = mime->urls();
  79. if (!urls.empty())
  80. {
  81. // Try to load the first URL as an image.
  82. // Modify imageLoaded according to
  83. // the success of this operation.
  84. imageLoaded = pix.load(urls[0].toLocalFile());
  85. }
  86. }
  87. // Is there an image present?
  88. else if (mime->hasImage())
  89. {
  90. // Convert the data to an QImage.
  91. // The construct qvariant_cast is used to convert
  92. // a stored value to another type.
  93. QImage img = qvariant_cast<QImage>(mime->imageData());
  94. // Load the QImage in a QPixmap.
  95. pix = QPixmap::fromImage(img);
  96. // Check if the pixmap is not blank.
  97. imageLoaded = !pix.isNull();
  98. }
  99.  
  100. QLabel* label = new QLabel;
  101. QString p=QString::number((int)this,16);
  102.  
  103. label->setText("pointerINDRAGENTEREVENT="+p);
  104. label->show();
  105.  
  106. // Only allow drops if the image loaded succesfully.
  107. event->setAccepted(imageLoaded);
  108. }
  109.  
  110. void DnDPixmap::dropEvent(QGraphicsSceneDragDropEvent *event)
  111. {
  112. QLabel* label = new QLabel;
  113. QString p=QString::number((int)this,16);
  114.  
  115. label->setText("pointerINDROPEVENT="+p);
  116. label->show();
  117. emit moveMade(/*x location where i drop my pixmap, havent found a simple way to get this*/,/*y location, description to the left, oudeX, oudeY);
  118.  
  119.   // Set the currently displayed pixmap to the dropped pixmap.
  120.   //setPixmap(pix);
  121. }
To copy to clipboard, switch view to plain text mode 

When I'm dragging and dropping my chesspiece the value of the this pointer changes, which to me aint logical.
Can someone clarify this to me please?
Thanks in advance!