Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. No drag target set ?

No drag target set ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 526 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • NevezN Offline
    NevezN Offline
    Nevez
    wrote on last edited by
    #1
    MainWindow(0x550db4f6b0, name="MainWindow") : No drag target set.
    

    Sometimes it gives this error when I drop a widget in a custom area set. I've looked on the net but couldn't find any documentation that directly explains this error.
    Why am I getting this error?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      How did you implement drag and drop ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • NevezN Offline
        NevezN Offline
        Nevez
        wrote on last edited by
        #3

        Hello, of course, if we briefly summarize the code;
        This is how I initiate a drag when the widget is clicked.

        if(widget == Q_NULLPTR)
                return;
            QByteArray byteArray(reinterpret_cast<char*>(&widget),sizeof(QWidget*));
            QDrag *drag = new QDrag(this);
            QMimeData * mimeData = new QMimeData;
            mimeData->setData("Label",byteArray);
            drag->setMimeData(mimeData);
            QPoint globalPos = mapToGlobal(pos);
            QPoint p = widget->mapFromGlobal(globalPos);
            drag->setHotSpot(p);
            drag->setPixmap(widget->grab());
            drag->exec(Qt::CopyAction | Qt::MoveAction);
        

        then I use dragenterevent and dropevent functions in the widget I will carry.
        DropEvent:

        if(event->mimeData()->hasFormat("Label") )   // in listwidget class
            {
                event->acceptProposedAction();
                QByteArray byteArray = event->mimeData()->data("Label");
                QWidget * widget = *reinterpret_cast<QWidget**>(byteArray.data());
                KrnLabel * new_label =  qobject_cast<KrnLabel *>(widget);
                   
                    QListWidgetItem *item = new QListWidgetItem();
                    QSize size = QSize(new_label->sizeHint().width()+15,new_label->sizeHint().height());
                    item->setSizeHint(size);
         
                    addItem(item);
                    setItemWidget(item,new_label );
                  
                
        
            }
            else
                event->ignore();
        }
        

        It doesn't always give this error. It only happens at certain times. For example, when I drag 7-8 widgets, I only get this error on one of them.
        Why am I getting this error randomly?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The implementation itself does not look wrong although I wouldn't move pointers to widget pointers around.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • NevezN Offline
            NevezN Offline
            Nevez
            wrote on last edited by
            #5

            @SGaist said in No drag target set ?:

            The implementation itself does not look wrong although I wouldn't move pointers to widget pointers around.

            could this be a bug?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I have a doubt that this is a bug.

              Can you provide a minimal compilable example that reliably shows this message ?

              By the way, which version of Qt are you using ?
              On which platform ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved