PDA

View Full Version : dropping on headerItem



drhex
30th June 2006, 17:06
Hi fellow hackers!

In QT-4.1.4, I'm trying to drop something on A QTreeWidget's headerItem(), with little success.

In the short example below, I can drag "Node 1" and "Node 2" and drop them on each other, but QT won't let me drop on the headerItem ("Node 0") even though I've set its ItemIsDropEnabled-flag. What can be done?



#include <QApplication>
#include <QTreeWidgetItem>

#define S(qstring) (qstring).toLatin1().constData()

class Tree : public QTreeWidget
{
public:
Tree() : QTreeWidget() {
setColumnCount(1);
setDragEnabled(true);
setAcceptDrops(true);
}
bool dropMimeData(QTreeWidgetItem *droppedOn, int, const QMimeData *, Qt::DropAction) {
qDebug("Something dropped on %s", S(droppedOn->text(0)));
return true;
}
};


int main( int argc, char **argv )
{
QApplication app( argc, argv );

QTreeWidget *tree = new Tree;

QTreeWidgetItem *i;

i = new QTreeWidgetItem(tree);
i->setText(0, "Node 1");
i->setFlags(i->flags() | Qt::ItemIsDropEnabled);

i = new QTreeWidgetItem(tree);
i->setText(0, "Node 2");
i->setFlags(i->flags() | Qt::ItemIsDropEnabled);

tree->headerItem()->setText(0,"Node 0");
tree->headerItem()->setFlags(tree->headerItem()->flags() | Qt::ItemIsDropEnabled);

tree->show();
app.exec();
return 0;
}

wysota
4th July 2006, 09:33
ItemIsDropEnabled means that you can drop some other item on this item and not that you can drop this item at all (ItemIsDragEnabled does that). I think that if you want to support dropping on headers, you have to reimplement the low level mechanisms for dropping (dragEnterEvent and family).