PDA

View Full Version : QtreeWidget drag and drop



addu
22nd June 2009, 21:32
Hi all


Please parden me ,if my question is silly..

How do implement the drag and drop for inside QTreewidget.. top toplevelitems only accept drops and if it have same item already it has to neglect it.. i tried with




void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
if (event->source() == this) {
event->setDropAction(Qt::MoveAction);
event->accept();
}
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
event->accept();

void MainWindow::dropEvent(QDropEvent *event)
{
if(ui->treeWidget->topLevelItem(1))
{
QByteArray ba;
// Create a data stream that operates on the binary data
QDataStream ds(&ba, QIODevice::WriteOnly);
// Add each item's text for col 0 to the stream
QMimeData *md = new QMimeData;
// Set the data associated with the mime type foo/bar to ba
md->setData("foo/bar", ba);

}
}



can you any one give a solution to implement the above senario

Advance Thanks

Thanks

Addu

shentian
22nd June 2009, 22:48
Use QAbstractItemView::setDragDropMode and QAbstractItemView::setDragEnabled to enable drag & drop on your QTreeWidget.

Use QStandardItem::setDropEnabled to allow/disallow drops on a specific item.

addu
23rd June 2009, 06:19
Hi All

I enbled the drag and drop for QTreeWidget ...

ui->treeWidget->dragDropOverwriteMode();
ui->treeWidget->setDragEnabled(true);
ui->treeWidget->setDragDropMode(QAbstractItemView ::InternalMove);

toplevelitems only accept the drops... I don't know how do implement..and if dropped itmes already is in toplevel childs ,it won't accept...

Some has replied using QStandardItem..

I created object for QStandardItem and i assined the the toplevelitem for object.. But it is giving errors.

Any suggestions are most Welcome..

Advance Thanks


Regards

Addu R

addu
29th June 2009, 14:15
Hi All


Still i am struggling with this issue...

please help me to solve this issue

Thanks

addu
30th June 2009, 10:41
Hi All

How do i set the DropEvent at TreeWidget for Accepting drops Toplevelitems only...

Please help me

Thanks in Advance