title: How to create a label with drag and drop function and with the clicked signal function QT
body: <p>I'm developing a program that contains a MainWindow and a Widget called Diagrama from <code>QWidget</code>, which is the central widget of my mainwindow.</p>
  <p>In this diagrama widget I have the ability to create a label in a the position that I clicked on the screen and the ability to drag an drop those same labels.</p>
  <p>But now, I want to add an ability to get a clicked signal of the label every time that I click it.</p>
  <p>I know that to enable the clicked signal function of a label, I have to create a class of a custom label, but when I do this and I replace the class <code>QLabel</code> to the customLabel class in the code, the drag and drop function stop working.</p>
  <pre class="lang-cpp prettyprint-override"><code>void Diagrama::dragEnterEvent(QDragEnterEvent *event)
  {....}
  
  void Diagrama::dragMoveEvent(QDragMoveEvent *event)
  {....}
  
  void Diagrama::dropEvent(QDropEvent *event)
  {....}
  
  void Diagrama::mousePressEvent(QMouseEvent *event)
  {....}
  </code></pre>
  <p>I put this for just you guys know that I have the function to the whole process</p>
  <p>And now I don't know what to do.
  I though that there is a conflict of the function <code>mousePressEvent</code> of my <code>customLabel</code> class and the same function in my <code>Diagrama</code> class.</p>
  <p>How can I solve it?</p>
  <hr />
  <pre class="lang-cpp prettyprint-override"><code>void Diagrama::dragMoveEvent(QDragMoveEvent *event)
  {
      if (event-&gt;mimeData()-&gt;hasFormat(&quot;application/x-dnditemdata&quot;)) {
          if (event-&gt;source() == this) {
              event-&gt;setDropAction(Qt::MoveAction);
              event-&gt;accept();
          } else {
              event-&gt;acceptProposedAction();
          }
      } else {
          event-&gt;ignore();
      }
  }
  
  void Diagrama::dropEvent(QDropEvent *event)
  {
      if (event-&gt;mimeData()-&gt;hasFormat(&quot;application/x-dnditemdata&quot;)) {
          QByteArray itemData = event-&gt;mimeData()-&gt;data(&quot;application/x-dnditemdata&quot;);
          QDataStream dataStream(&amp;itemData, QIODevice::ReadOnly);
  
          QPixmap pixmap;
          QPoint offset;
          dataStream &gt;&gt; pixmap &gt;&gt; offset;
  
          QLabel *newIcon = new QLabel(this);
          newIcon-&gt;setPixmap(pixmap);
          newIcon-&gt;move(event-&gt;pos() - offset);
          newIcon-&gt;show();
          newIcon-&gt;setAttribute(Qt::WA_DeleteOnClose);
  
          if (event-&gt;source() == this) {
              event-&gt;setDropAction(Qt::MoveAction);
              event-&gt;accept();
          } else {
              event-&gt;acceptProposedAction();
          }
      } else {
          event-&gt;ignore();
      }
  }
  
  void Diagrama::paintEvent(QPaintEvent *e)
  {
      QPainter painter(this);
      painter.drawImage(0,0,*mImage);
      e-&gt;accept();
  }
  
  void Diagrama::mousePressEvent(QMouseEvent *event)
  {
  
  
      if(modo==&quot;trafo&quot;)
      {
          if(event-&gt;button()==Qt::LeftButton){
              QLabel *child = static_cast&lt;QLabel*&gt;(childAt(event-&gt;pos()));
              if (!child)
                  return;
  
              QPixmap pixmap = *child-&gt;pixmap();
  
              QByteArray itemData;
              QDataStream dataStream(&amp;itemData, QIODevice::WriteOnly);
              dataStream &lt;&lt; pixmap &lt;&lt; QPoint(event-&gt;pos() - child-&gt;pos());
  
              QMimeData *mimeData = new QMimeData;
              mimeData-&gt;setData(&quot;application/x-dnditemdata&quot;, itemData);
  
              QDrag *drag = new QDrag(this);
              drag-&gt;setMimeData(mimeData);
              drag-&gt;setPixmap(pixmap);
              drag-&gt;setHotSpot(event-&gt;pos() - child-&gt;pos());
  
              QPixmap tempPixmap = pixmap;
              QPainter painter;
              painter.begin(&amp;tempPixmap);
              painter.fillRect(pixmap.rect(), QColor(127, 127, 127, 127));
              painter.end();
  
              child-&gt;setPixmap(tempPixmap);
  
              if (drag-&gt;exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction) {
                  child-&gt;close();
              } else {
                  child-&gt;show();
                  child-&gt;setPixmap(pixmap);
              }
          }
          else if(event-&gt;button()==Qt::RightButton)
          {
  
              QLabel *child = new QLabel(this);
              child-&gt;setPixmap(QPixmap(url_trafo));
              child-&gt;move(event-&gt;x(),event-&gt;y());
              child-&gt;show();
  
          }
  
      }
      else if(modo==&quot;linha&quot;)
      {
          if(event-&gt;button()==Qt::RightButton){
              p_ini=event-&gt;pos();
               drawing=true;
              event-&gt;accept();}
  
          else {
              event-&gt;ignore();
              drawing=false;
          }
      }
  
  }
  </code></pre>
  <p>That is the responsible for the events of drag and drop and the event of appearing a label every time I click on the screen</p>
  <p>I tried to create a customLabel class to emit a clicked signal every time I click in the label, but disable the drag and drop event</p>