It seems there is something wrong here and it's creating another problem.

Qt Code:
  1. void DragWidget::mousePressEvent(QMouseEvent *event)
  2. {
  3.  
  4. // Pack mime data
  5. QMimeData *mimeData = new QMimeData;
  6. mimeData->setColorData(QVariant(myColor));
  7.  
  8. // Prepare cursor image
  9. QPixmap pixmap(this->size());
  10. QPainter painter;
  11. painter.begin(&pixmap);
  12. painter.fillRect(pixmap.rect(), myColor);
  13. painter.end();
  14.  
  15. // We establish QDrag object, draw cursor and embed data
  16. QDrag *drag = new QDrag(this);
  17. drag->setMimeData(mimeData);
  18. drag->setPixmap(pixmap);
  19. drag->setHotSpot(event->pos());
  20.  
  21. sourcePicker = drag->source();
  22.  
  23. // We send it
  24. drag->exec(Qt::CopyAction);
  25.  
  26.  
  27. }
  28.  
  29. void DragWidget::mouseReleaseEvent(QMouseEvent *event)
  30. {
  31.  
  32. if (event->type() == QEvent::MouseButtonRelease){
  33. QColor color = QColorDialog::getColor(QColor(myColor), this);
  34. if (color.isValid()) {
  35. setPalette(QPalette(color));
  36. setAutoFillBackground(true);
  37. myColor = color;
  38. }
  39. }
  40. else
  41. event->ignore();
  42. }
To copy to clipboard, switch view to plain text mode 

With this line in "mousePressEvent":
Qt Code:
  1. drag->exec(Qt::CopyAction);
To copy to clipboard, switch view to plain text mode 
drag n drop is working fine but "mouseReleaseEvent" is not getting called. If I comment this
line "releaseEvent" is getting called.

Secondly, I have to add the functionality to make this widget as color picker also, I added color picking dialog in "releaseEvent". This won't work as expected because the "dropping"
event is actually a "releaseEvent" and as you drop on target picker dialog shows up.

A hack to this problem is to show color dialog when there is "down" and "up" on same widget. Using a bool var, you set state true, when there is a mouse down and in mouse up
event, check the state of this var, if it's true, show color dialog and set it again to false.
Am I right here or there is a better way of doing this?

How do I setup a menu, which appears at dropping? "swap color" or "replace color"

Prashant