Hi
I try to implement to drop files from the windows explorer to a QTreeWidget (this one is subclassed clsMyTree (I need such feature to open the files and extract data to fill the tree).
The problem that I have is that couldn't found any way to accept the QTreeWidget to see the drop object.
See some test class below:
///////////////////start class //////////////////////////
///////////header file//////
#include <QtGui/QApplication>
#include <QtGui/QTreeWidget>
class clsMyTree :
{
Q_OBJECT
public:
clsMyTree(void);
clsMyTree
( QWidget *p
=0);
//: QTreeWidget(p) { } virtual ~clsMyTree(void);
protected:
virtual bool event
(QEvent *event
);
public slots:
void setValue();
signals:
void valueChanged(int newValue);
};
///////////cpp file//////
#include "heaMyTree.h"
#include <QDropEvent>
clsMyTree::clsMyTree(void)
{
}
setAcceptDrops(true);
p->setAcceptDrops(true);
}
clsMyTree::~clsMyTree(void)
{
}
parent=parent;
return true;
}
bool clsMyTree
::event(QEvent *event
) {
if (event
->type
() == QEvent::Drop) { Qt::DropAction dropAct=pEv->dropAction ();
long lActio=0;
lActio=dropAct;
}
}
void clsMyTree::setValue()
{
}
///////////////////end class //////////////////////////
///////////////////start class //////////////////////////
///////////header file//////
#include <QtGui/QApplication>
#include <QtGui/QTreeWidget>
class clsMyTree :
public QTreeWidget
{
Q_OBJECT
public:
clsMyTree(void);
clsMyTree( QWidget *p=0); //: QTreeWidget(p) { }
virtual ~clsMyTree(void);
protected:
virtual bool event(QEvent *event);
virtual bool dropMimeData ( QTreeWidgetItem * parent, int index, const QMimeData * data, Qt::DropAction action );
public slots:
void setValue();
signals:
void valueChanged(int newValue);
};
///////////cpp file//////
#include "heaMyTree.h"
#include <QDropEvent>
clsMyTree::clsMyTree(void)
{
}
clsMyTree::clsMyTree( QWidget *p) : QTreeWidget(p) {
setAcceptDrops(true);
p->setAcceptDrops(true);
}
clsMyTree::~clsMyTree(void)
{
}
bool clsMyTree::dropMimeData ( QTreeWidgetItem * parent, int index, const QMimeData * data, Qt::DropAction action ){
parent=parent;
return true;
}
bool clsMyTree::event(QEvent *event)
{
if (event->type() == QEvent::Drop) {
QDropEvent *pEv=static_cast<QDropEvent *>(event);
Qt::DropAction dropAct=pEv->dropAction ();
long lActio=0;
lActio=dropAct;
}
return QWidget::event(event);
}
void clsMyTree::setValue()
{
}
///////////////////end class //////////////////////////
To copy to clipboard, switch view to plain text mode
With this example I catch one file from the windows explorer and try to drop it into the clsMyTree(inherited from QTreeWidget) and no event happen in my reimplemented functions ::event,dropMimeData and so on. Nor he display me the right mousecursor.
For me it looks like the widget are not right enabled for dropping objects that are
incomming out from another application. In this case windows explorer.
I there somebody that have experience with such kind of works?
Is the QTreeWidget the right widget for such things and is my implementation right or maybe I forgote something others?
PS: The example was done with QT 4.1 and Visual Studio 2003. For the main
widget I use also the designer. But unfortunately the new designer is for
such works, especially for this drag and drop problem, not really
helpfully.
In the mean time I try to do this with KDevelop and KDE in Linux.
I would really appreciate any helps.
Thanks
Piero
Bookmarks