Thanks, I thought it was supposed to be like that, but for some reason when I start a drag I don't see the mimedata function get called, and when I do a drop I don't see the text that I've written into the mimeData output.
SigTreeWidget is just being defined as:
{
Q_OBJECT
public:
explicit SigTreeWidget
(QWidget *parent
= 0);
Q_SIGNALS:
public Q_SLOTS:
void SelectedSigsDnDHelper(); //Stores the TreeWidget's selected signals in a string when selection changes
private:
std::string selectedSignals;
QMimeData *mimeData
(const QModelIndexList
&indexes
) const;
};
class SigTreeWidget : public QTreeWidget
{
Q_OBJECT
public:
explicit SigTreeWidget(QWidget *parent = 0);
Q_SIGNALS:
public Q_SLOTS:
void SelectedSigsDnDHelper(); //Stores the TreeWidget's selected signals in a string when selection changes
private:
QPoint dragStartPosition;
std::string selectedSignals;
QStringList mimeTypes() const;
QMimeData *mimeData(const QModelIndexList &indexes) const;
};
To copy to clipboard, switch view to plain text mode
With the full implementation below:
SigTreeWidget
::SigTreeWidget(QWidget *parent
) :{
}
void SigTreeWidget::SelectedSigsDnDHelper()
{
QList<QTreeWidgetItem *> itemList = this->selectedItems();
selectedSignals.clear();
while (!itemList.isEmpty())
{
selectedSignals += itemList.takeFirst()->text(1).toStdString() + ".";
}
if (!selectedSignals.empty())
selectedSignals.pop_back();
// std::cerr << "Selected Signals = " << selectedSignals << std::endl;
}
{
std::cerr << "mimeTypes" << std::endl;
types << "application/vnd.text.list";
return types;
}
QMimeData *SigTreeWidget
::mimeData(const QModelIndexList
&indexes
) const {
std::cerr << "mimeData" << std::endl;
stream << selectedSignals.data();
mimeData->setData("application/vnd.text.list", encodedData);
return mimeData;
}
SigTreeWidget::SigTreeWidget(QWidget *parent) :
QTreeWidget(parent)
{
}
void SigTreeWidget::SelectedSigsDnDHelper()
{
QList<QTreeWidgetItem *> itemList = this->selectedItems();
selectedSignals.clear();
while (!itemList.isEmpty())
{
selectedSignals += itemList.takeFirst()->text(1).toStdString() + ".";
}
if (!selectedSignals.empty())
selectedSignals.pop_back();
// std::cerr << "Selected Signals = " << selectedSignals << std::endl;
}
QStringList SigTreeWidget::mimeTypes() const
{
std::cerr << "mimeTypes" << std::endl;
QStringList types;
types << "application/vnd.text.list";
return types;
}
QMimeData *SigTreeWidget::mimeData(const QModelIndexList &indexes) const
{
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
When I start a drag in the compiled version I see "mimeTypes" output to console, but I never see "mimeData" is why I was wondering when mimeData() is called originally, but from your answer I still don't know why I don't see the mimeData I want being attached to the drag.
Bookmarks