Hi.
Before I forget: I'm using Qt 4.8.1, built using gcc 4.5.3 and QtCreator
2.5.0 under Linux (Gentoo).
Although I have managed in the past, somehow, to make the drop indicator to
appear, now id does not anymore.
I am dragging items from a custom toolbox page created programatically.
There, on a "mouseMove" event, the program checks if the left mouse button
is pressed, and only then it creates a new QDrag and a mimeData:
void CToolTableWidget::mouseMoveEvent ( QMouseEvent * event ) {
if ( (event->buttons() == Qt::LeftButton) &&
(mDragStartPos - event->pos()).manhattanLength() >=
QApplication::startDragDistance() ) {
QDrag * drag = new QDrag(this);
QMimeData * mimeData = new QMimeData;
int row = itemAt(mDragStartPos)->row();
QString toolType = item(row,1)->text();
QString toolName = item(row,2)->text();
QString toolIcon = item(row,3)->text();
mimeData->setImageData(item(row,0)->icon());
mimeData->setText(QString("%1@%2").arg(toolType).arg(toolName));
drag->setPixmap(toolIcon);
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction, Qt::CopyAction);
}
// QTableWidget::mouseMoveEvent(event);
}
void CToolTableWidget::mousePressEvent ( QMouseEvent * event ) {
if (event->button() == Qt::LeftButton)
mDragStartPos = event->pos();
QTableWidget::mousePressEvent(event);
}
void CToolTableWidget::mouseReleaseEvent ( QMouseEvent * /*event*/ ) {
}
It works fine, as I can see the dragged icon and the drag action overlay.
Now, on the custom QTreeView, I have "setDropIndicatorShown(true)" on the
constructor, and this:
void CTreeViewTest::dragEnterEvent(QDragEnterEvent *event) {
if (event->mimeData()->hasFormat("text/plain") ) {
QString st = event->mimeData()->text();
CToolInfo * toolInfo = new CToolInfo();
if ( st.mid(0,st.indexOf("@")) >=
toolInfo->toolTypeString(CToolInfo::GENERATOR) ) {
setDropIndicatorShown(true);
event->acceptProposedAction();
event->accept();
} else {
event->setDropAction(Qt::IgnoreAction);
}
}
}
void CTreeViewTest::dragMoveEvent(QDragMoveEvent *event) {
if (event->mimeData()->hasFormat("text/plain") ) {
QString st = event->mimeData()->text();
CToolInfo * toolInfo = new CToolInfo();
if ( st.mid(0,st.indexOf("@")) >=
toolInfo->toolTypeString(CToolInfo::GENERATOR) ) {
setDropIndicatorShown(true);
event->acceptProposedAction();
event->accept();
}
}
}
void CTreeViewTest::dropEvent(QDropEvent *event) {
if (event->mimeData()->hasFormat("text/plain") ) {
event->setDropAction(Qt::CopyAction);
QString st = event->mimeData()->text();
CToolInfo * toolInfo = new CToolInfo();
if ( st.mid(0,st.indexOf("@")) ==
toolInfo->toolTypeString(CToolInfo::GENERATOR) ) {
event->accept();
st = st.mid(st.indexOf("@") + 1, st.length() - st.indexOf("@"));
// mCounter++;
emit droppedData(&st, mCounter);
}
}
}
The mime data can be retrieved on the drop event, the drag-drop action
overlay is present (it was already changed just to check where did id come
from), but no drop indication, and I need it because the tree items may
have children items dropped to.
Any hint? Am I (probably) missing something?
Thanks
Francisco
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest