Thanks for the quick reply. I've changed my mimeData() header and function definition to below, but I still don't see it getting called when I do a drag, only the mimeTypes() function:
Header:
{
Q_OBJECT
public:
explicit SigTreeWidget
(QWidget *parent
= 0);
Q_SIGNALS:
public Q_SLOTS:
void SelectedSigsDnDHelper();
private:
std::string selectedSignals;
QMimeData * mimeData
(const QList<QTreeWidgetItem
*>
& items
) const;
};
class SigTreeWidget : public QTreeWidget
{
Q_OBJECT
public:
explicit SigTreeWidget(QWidget *parent = 0);
Q_SIGNALS:
public Q_SLOTS:
void SelectedSigsDnDHelper();
private:
QPoint dragStartPosition;
std::string selectedSignals;
QStringList mimeTypes() const;
QMimeData * mimeData(const QList<QTreeWidgetItem *> & items) const;
};
To copy to clipboard, switch view to plain text mode
Function Definition:
QMimeData *SigTreeWidget
::mimeData(const QList<QTreeWidgetItem
*>
& items
) const {
(void)items;
std::cerr << "mimeData" << std::endl;
stream << selectedSignals.data();
mimeData->setData("application/vnd.text.list", encodedData);
return mimeData;
}
QMimeData *SigTreeWidget::mimeData(const QList<QTreeWidgetItem *> & items) const
{
(void)items;
std::cerr << "mimeData" << std::endl;
QMimeData *mimeData = new QMimeData();
QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
stream << selectedSignals.data();
mimeData->setData("application/vnd.text.list", encodedData);
return mimeData;
}
To copy to clipboard, switch view to plain text mode
Everything else has stayed the same as my last post
Maybe I need something else when I create the SigTreeWidget to enable drag? I've included the code where I create the SigTreeWidget below as well since maybe I'm missing something there too:
// Instantiate the tree Widget
signalTreeWidget = new SigTreeWidget();
signalTreeWidget->setColumnCount(2);
signalTreeWidget->setHeaderHidden(true);
signalTreeWidget->setColumnHidden(1, true);
signalTreeWidget->setDragEnabled(true);
signalTreeWidget->expandAll();
connect(signalTreeWidget, SIGNAL(itemSelectionChanged()), signalTreeWidget, SLOT(SelectedSigsDnDHelper()));
}
// Instantiate the tree Widget
signalTreeWidget = new SigTreeWidget();
signalTreeWidget->setColumnCount(2);
signalTreeWidget->setHeaderHidden(true);
signalTreeWidget->setColumnHidden(1, true);
signalTreeWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
signalTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
signalTreeWidget->setDragEnabled(true);
signalTreeWidget->setDragDropMode(QAbstractItemView::DragOnly);
signalTreeWidget->expandAll();
connect(signalTreeWidget, SIGNAL(itemSelectionChanged()), signalTreeWidget, SLOT(SelectedSigsDnDHelper()));
}
To copy to clipboard, switch view to plain text mode
I populate this tree using the selected items in another QTreeWidget though unless you think that part is necessary to include I'll omit it here
Added after 16 minutes:
I found the last reason, it was because I needed the Qt 4.8 header that is
QMimeData * QTreeWidget::mimeData(const QList<QTreeWidgetItem *> items) const
To copy to clipboard, switch view to plain text mode
instead of
QMimeData * QTreeWidget::mimeData(const QList<QTreeWidgetItem *> [B]&[/B] items) const
To copy to clipboard, switch view to plain text mode
My Qt creator says it's based on Qt 5.2.1 so I thought I had to use the Qt 5 documentation but I guess I'm somehow compiling against Qt 4.8 instead.
Anyways thanks for all the help!
Bookmarks