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. Drag and drop from QToolBar to QGraphicsView is not working properly
Forum Updated to NodeBB v4.3 + New Features

Drag and drop from QToolBar to QGraphicsView is not working properly

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 913 Views 2 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.
  • S Offline
    S Offline
    surajeet
    wrote on last edited by surajeet
    #1

    I am working on a project using Qt C++ . I have a QToolBar which contains some QButtons (read as QAction) and a QGraphicsView (the whole bottom part).
    It looks like this.

    enter image description here

    Now, I want to drag a QButton (read as QAction) from the QToolBar into central window (which actually is QGraphicsView) of my application.

    Till now I have written the following SLOT for corresponding QAction to enable dragging and dropping.

    /* Send_Message is one of the actions */
    void CTestBuilderApp::on_actionSend_Message_triggered()
    {    
        QByteArray itemData;    
        QDataStream dataStream(&itemData, QIODevice::WriteOnly);    
        emit selectionState(None); 
    
        dataStream << "Send Message";    
        
        QMimeData *mimeData = new QMimeData;    
        mimeData->setData("application/x-dnditemdata", itemData);    
        
        QDrag *drag = new QDrag(this);    
        drag->setMimeData(mimeData);    
        drag->setPixmap(ui->ToolBox->actions().at->icon().pixmap(48,48));    
        drag->exec(Qt::CopyAction, Qt::CopyAction);    
        qDebug()<<"drag complete";
    } 
    

    But, as this SLOT is being called only when I am clicking on the QAction, I am not getting the proper effect of Drag and Drop. When I am clicking the button, only then the dragging is starting. One click on the QAction and then another click on QGraphicsView is doing the job, but it's not what it's supposed to be for drag & drop. It's not starting on pressing and then dragging.

    Is there any way out to make this code work? I am searching for some SLOT that get called as soon as I press on the QAction i.e. it does not wait for Mouse Release to work.

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

      Hi,

      If you want to customise the drag and drop you'll need to either use a custom QToolBar implementing the technique described in the Drag and Drop documentation.

      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