Re: Drag and drop revisited
It doesn't get called probably because you reimplemented the other methods. According to my belief, you should reimplement dropMimeData(), mimeData() and mimeTypes() from in model class.
Re: Drag and drop revisited
Hi, I made some great progress. I've a line drawn where the item is placed. And I can pass the row index of the item to be moved.
May be useful for to someone, very similiar to Amarok(music player) playlist drag and drop.
Without the actual moving of items yet.
I guess a custom mime type would be best to stop unwanted drops and drags
Code:
{
list << "text/plain";
return list;
}
void MyModel::emit_layoutChanged ( )
{
emit layoutChanged();
}
{
if (event->button() == Qt::LeftButton) {
QString plainText
= lexical_cast<std
::string>
(index.
row()).
c_str();
mimeData->setText(plainText);
drag->setMimeData(mimeData);
drag->setHotSpot(event->pos() - rect().topLeft());
dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
}
}
{
if (event->mimeData()->hasText())
event->acceptProposedAction();
else
event->ignore();
}
{
if (event->mimeData()->hasText()) {
event->setDropAction(Qt::MoveAction);
std::string text = (event->mimeData()->text()).toStdString();
std::cout << text << std::endl;
}
else {
event->ignore();
}
}
{
dropSite = event->answerRect();
model_->emit_layoutChanged(); // public function in model subclass
}
{
int x, y, w, h;
dropSite.getRect ( &x, &y, &w, &h );
QRect arect
= visualRect
( modidx
);
int b = arect.y();
QBrush brush
(Qt
::black, Qt
::Dense4Pattern);
pen.setWidth(2);
pen.setBrush(brush);
painter.setPen(pen);
painter.drawLine ( 0, b, width(), b );
event->accept();
}