PDA

View Full Version : QTreeView Drag and Drop



NIteLordz
9th October 2016, 16:32
Currently i am able to drag an item from a QListView into a QTreeView. Now i am trying to visualize the drag and drop, and have run into a problem.

In dragMoveEvent i get a copy of event->answerRect() and then i use it in the paintEvent. See below code.


void SceneTreeView::paintEvent(QPaintEvent* event) {
QPainter painter(viewport());

QModelIndex modelIndex = indexAt(QPoint(dropSite_.x(), dropSite_.y()));
QRect answerRect = visualRect(modelIndex);

QBrush brush(Qt::black, Qt::Dense4Pattern);

QPen pen;
pen.setWidth(2);
pen.setBrush(brush);

painter.setPen(pen);
painter.drawRect(answerRect);

QTreeView::paintEvent(event);

event->accept();
}

This will draw a box around the entire item within the SceneTreeView, but only if the cursor is on the edge of the widget. if i hover the mouse over the middle of the widget, where the actual item is displayed, the box does not update, only when i move it to the right, and approach the border.

thoughts ?