[Qt-interest] invalid use of incomplete type ‘struct QGraphicsSceneDragDropEvent’
Riccardo Roasio
riccardo.roasio at gmail.com
Thu Sep 10 14:36:18 CEST 2009
Hi,
i'm trying to use the drag and drop functionality of the QGraphicItem class,
but it's giving me this error:
invalid use of incomplete type ‘struct QGraphicsSceneDragDropEvent’
Can anyone help me to solve this problem?
Thanks so much
Riccardo
Here is the small code i'm trying to run:
#ifndef TABLE_H
#define TABLE_H
#include <QGraphicsItem>
class Table : public QGraphicsItem
{
public:
Table();
QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem
*option, QWidget *widget);
protected:
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
void dropEvent(QGraphicsSceneDragDropEvent *event);
bool dragOver;
private:
qreal angle;
int width;
int height;
int x;
int y;
int diameter;
bool rounded;
QColor color;
};
#endif // TABLE_H
#include "table.h"
#include <QGraphicsScene>
#include <QPainter>
#include <QStyleOption>
#include <math.h>
static const double Pi = 3.14159265358979323846264338327950288419717;
static double TwoPi = 2.0 * Pi;
static qreal normalizeAngle(qreal angle)
{
while (angle < 0)
angle += TwoPi;
while (angle > TwoPi)
angle -= TwoPi;
return angle;
}
Table::Table()
{
angle=0;
color=qrand() % 256;
width=200;
height=100;
rounded=false;
diameter=0;
x=50;
y=50;
setAcceptDrops(true);
}
QRectF Table::boundingRect() const
{
qreal adjust = 0.5;
return QRectF(-18 - adjust, -22 - adjust,
36 + adjust, 60 + adjust);
}
QPainterPath Table::shape() const
{
QPainterPath path;
path.addRect(-10, -20, 20, 40);
return path;
}
void Table::paint(QPainter *painter, const QStyleOptionGraphicsItem
*, QWidget *)
{
// Draw Table
painter->setBrush(color);
painter->drawRect ( x, y, width, height );
}
void Table::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
event->setAccepted(true);
dragOver = true;
update();
}
void Table::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
{
Q_UNUSED(event);
dragOver = false;
update();
}
void Table::dropEvent(QGraphicsSceneDragDropEvent *event)
{
dragOver = false;
update();
}
#include <QtGui/QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include "table.h"
#include <math.h>
int main(int argc, char *argv[])
{
QApplication application(argc, argv);
QGraphicsScene scene;
scene.setSceneRect(0, 0, 1000, 760);
scene.setItemIndexMethod(QGraphicsScene::NoIndex);
Table *table = new Table;
scene.addItem(table);
QGraphicsView view(&scene);
view.setRenderHint(QPainter::Antialiasing);
// view.setBackgroundBrush(QPixmap(":/images/cheese.jpg"));
view.setCacheMode(QGraphicsView::CacheBackground);
view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
view.setDragMode(QGraphicsView::ScrollHandDrag);
view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Osty"));
view.resize(1024, 768);
view.show();
return application.exec();
}
More information about the Qt-interest-old
mailing list