Originally Posted by
inktomi
This is not the actual code. It is just a demo that shows the problem.
Well then it doesn't show the problem.
What do you mean nothing gets called? The drag events are working fine, the problem seems to be that the paint event does not get called whilst dragging.
This is a direct wrap of your code to make it compilable, run it and see if you get any output. If you want help, provide something meaningful.
#include <QDrag>
#include <QDragEnterEvent>
#include <QPainter>
#include <QDebug>
#include <QApplication>
#include <QTreeWidget>
public:
protected:
};
{
setDragEnabled(true);
setAcceptDrops(true);
}
{
qDebug() << Q_FUNC_INFO;
drag->exec();
}
{
qDebug() << Q_FUNC_INFO;
event->accept();
}
{
qDebug() << Q_FUNC_INFO;
repaint();
}
{
qDebug() << Q_FUNC_INFO;
painter.setPen(Qt::gray);
painter.
drawEllipse(QPointF(qrand
() % width
(), qrand
() % height
()),
5,
5);
}
int main(int argc, char **argv){
w.show();
return app.exec();
}
#include <QDrag>
#include <QDragEnterEvent>
#include <QPainter>
#include <QDebug>
#include <QApplication>
#include <QTreeWidget>
class Tree : public QTreeWidget {
public:
Tree(QWidget *parent = 0);
protected:
void mousePressEvent(QMouseEvent*);
void dragEnterEvent(QDragEnterEvent*);
void dragMoveEvent(QDragMoveEvent*);
void paintEvent(QPaintEvent*);
};
Tree::Tree(QWidget *parent) :
QTreeWidget(parent)
{
setDragEnabled(true);
setAcceptDrops(true);
}
void Tree::mousePressEvent(QMouseEvent *event)
{
qDebug() << Q_FUNC_INFO;
QDrag *drag = new QDrag(this);
drag->setMimeData(new QMimeData());
drag->exec();
}
void Tree::dragEnterEvent(QDragEnterEvent *event)
{
qDebug() << Q_FUNC_INFO;
event->accept();
}
void Tree::dragMoveEvent(QDragMoveEvent *)
{
qDebug() << Q_FUNC_INFO;
repaint();
}
void Tree::paintEvent(QPaintEvent *event)
{
qDebug() << Q_FUNC_INFO;
QTreeWidget::paintEvent(event);
QPainter painter(viewport());
painter.setPen(Qt::gray);
painter.drawEllipse(QPointF(qrand() % width(), qrand() % height()), 5, 5);
}
int main(int argc, char **argv){
QApplication app(argc, argv);
QTreeWidget w;
w.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
And it's not a bug in Qt, it's a bug in your thinking, if I understand the problem correctly. But before I share what I know, I want to see the situation clearly because the code you posted doesn't describe it.
Bookmarks