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. Handle rejected dropEvent

Handle rejected dropEvent

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.1k 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.
  • M Offline
    M Offline
    Marcos Modenesi
    wrote on last edited by
    #1

    I'm implementing drag and drop on a QTableWidget and I want to prevent the user from dropping on some cells (depending on various factors). I can only detect if the drop will be allowed when the user tries to drop on a cartain cell. Then I perform some tests and ignore or accept the event in dropAction(QDropEvent *event).
    Basically, my problem is that I can't detect whether the dropAction was ignored from within the startDrag function.
    I'm really stranged, since I've been developping this on Ubuntu and it worked perfectly. The problem appaired when I tryed to build on Windows.

    Briefly, theese are the functions I have:

    @void TablaCentral::startDrag()
    {
    QTableWidgetItem item = currentItem();
    if (/
    item gathers some conditions */){
    QMimeData *mimeData = new QMimeData;
    ...
    QDrag *drag = new QDrag(this);
    drag->setMimeData(mimeData);
    ...
    if(drag->exec() == Qt::MoveAction){ // <-- <-- <-- I'm stuck here

               // it alywas enters here, don't know how to 
               // recongize an ignored dropEvent
    
        } else {
    
             // never enters here!!
             // I supposed it should enter here if I ignore on dropEvent(...&#41;
    
        }
    }
    

    }

    void TablaCentral::dragEnterEvent(QDragEnterEvent *event)
    {
    if (event->source() == this){
    event->setDropAction(Qt::MoveAction);
    event->accept();
    }
    }

    void TablaCentral::dragMoveEvent(QDragMoveEvent *event)
    {
    if(event->source() == this){
    event->setDropAction(Qt::MoveAction);
    event->accept();
    }
    }

    void TablaCentral::dropEvent(QDropEvent *event)
    {
    if(event->source() == this){
    QTableWidgetItem targetItem = itemAt(event->pos());
    if ( /
    targetItem doesn't gather some conditions */ ){
    event->ignore();
    return;
    }
    if (/some other conditions/){
    event->ignore();
    return;
    } else {
    // do something with the data
    event->accept();
    // this is the only case when I accept
    }
    }@

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Marcos Modenesi
      wrote on last edited by
      #2

      Found it on "this document.":http://qt-project.org/doc/qt-4.8/dnd.html Apparently, event->ignore() wasn't enough. I replaced it every time on dropEvent(QDropEvent *event) whith this:

      @
      event->setDropAction(Qt::IgnoreAction);
      event->ignore();
      @

      Still it's odd to me how the problem didn't show up on Linux...

      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