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. Highlight items of treeview during Drag n Drop
Qt 6.11 is out! See what's new in the release blog

Highlight items of treeview during Drag n Drop

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.2k 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.
  • S Offline
    S Offline
    scayetanot
    wrote on last edited by
    #1

    Hi,

    i have tried to highlight the item I'm currently hover when moving the mouse during a DnD.

    By the way, it doesn't work. It doesn't work during the Drag'Drop but only after when no more DnD but just mouse move. I just want the highlight when DnD and not before or after

    I have enable the highlight by:

    @void TreeView::dragMoveEvent(QDragMoveEvent * event)
    {
    qDebug() << "On Drag Move Event";
    const QMimeData* mimeData = event->mimeData();

    event->setDropAction(Qt::CopyAction);
    
    if (mimeData->hasUrls())
    {
        QTreeWidgetItem *item = itemAt(event->pos());
        if(item) {
            qDebug() << "itemat: " << item->text(0);
    

    #if 0
    setStyleSheet(QString::fromUtf8("QTreeWidget::item:hover {\n"
    "background-color: rgb(123, 45, 67);\n"
    "}"));
    #endif
    }
    event->setDropAction(Qt::CopyAction);
    event->acceptProposedAction();
    }
    else
    event->ignore();

    // dropSite = event->answerRect();
    // event->acceptProposedAction();
    }@

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DBoosalis
      wrote on last edited by
      #2

      I would suggest you use your own Delegate and handle the styling in its paint() method.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        scayetanot
        wrote on last edited by
        #3

        I tried to implement something with :

        @void TreeView::paintEvent ( QPaintEvent* event )
        {
        QTreeView::paintEvent (event);
        QPainter painter ( viewport() );
        int x, y, w, h;
        dropSite.getRect ( &x, &y, &w, &h );
        QPoint point(x,y);
        QModelIndex modidx = indexAt ( point );
        QRect arect = visualRect ( modidx );
        int b = arect.y();
        QBrush brush(Qt::black, Qt::Dense4Pattern);
        QPen pen;
        pen.setWidth(2);
        pen.setBrush(brush);
        painter.setPen(pen);
        painter.drawLine ( 0, b, width(), b );
        event->accept();
        }@

        but it's not really working fine. if you can point me to an example using QtreeWidget it will be perfect.

        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