Thank you,
it's possible to add those new selected items to the list returned by selectedItems ?
Basically now I have implemented this code:
void ReportsTreeWidget::startDrag(Qt::DropActions supportedActions)
{
Q_UNUSED(supportedActions)
if (selectedItems().empty())
{
return;
}
// ... more code ...
// I iterate over the selected items
{
// If top-level item then drag its children, not the item itself
if (!item->parent())
{
auto children = item->childCount();
for (auto child = 0; child < children; ++child)
{
if (pChild != nullptr)
{
pChild->setSelected(true);
}
}
item->setSelected(false);
}
// ... more code ...
mimeData->setText(data);
Drag drag(this);
drag.setMimeData(mimeData);
drag.setPixmap(dragPixmap);
drag.exec(Qt::CopyAction);
}
void ReportsTreeWidget::startDrag(Qt::DropActions supportedActions)
{
Q_UNUSED(supportedActions)
if (selectedItems().empty())
{
return;
}
// ... more code ...
// I iterate over the selected items
for (QTreeWidgetItem *item : selectedItems())
{
// If top-level item then drag its children, not the item itself
if (!item->parent())
{
auto children = item->childCount();
for (auto child = 0; child < children; ++child)
{
QTreeWidgetItem *pChild = item->child(child);
if (pChild != nullptr)
{
pChild->setSelected(true);
}
}
item->setSelected(false);
}
// ... more code ...
QMimeData *mimeData = new QMimeData;
mimeData->setText(data);
Drag drag(this);
drag.setMimeData(mimeData);
drag.setPixmap(dragPixmap);
drag.exec(Qt::CopyAction);
}
To copy to clipboard, switch view to plain text mode
I compose "data" from the selected items that I get with the method selectedItems() in the for loop.
I would add the new selected items (in the inner if) so that I can add them to the list. The items are not moved, but copied.
Franco
Bookmarks