Thanks thawkins, but I think it´s not exactly what I need.
I have followed the mice colliding example and I´ve created a timer event:
The .h file:
#ifndef CHIP_H
#define CHIP_H
#include <QtGui/QColor>
#include <QtGui/QGraphicsItem>
#include <QObject>
{
Q_OBJECT
public:
Chip
(const QColor &color,
int x,
int y,
const QString &tipo,
const qreal
&ancho,
const qreal
&alto,
const QPixmap &pixmap
);
protected:
[/B]
private:
int x, y;
qreal ancho;
qreal alto;
QList<QPointF> stuff;
};
#ifndef CHIP_H
#define CHIP_H
#include <QtGui/QColor>
#include <QtGui/QGraphicsItem>
#include <QObject>
class Chip : public QGraphicsItem
{
Q_OBJECT
public:
Chip(const QColor &color, int x, int y, const QString &tipo, const qreal &ancho, const qreal &alto, const QPixmap &pixmap);
QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void timerEvent(QTimerEvent *event);
[/B]
private:
int x, y;
QColor color;
QString tipo;
QPixmap pixmap;
qreal ancho;
qreal alto;
QList<QPointF> stuff;
};
To copy to clipboard, switch view to plain text mode
And in the .cpp file I have reimplemented the timer event:
#include "chip.h"
#include "loc.h"
#include <QtGui>
#include <QtSql>
loc_position_t loc_pos;
Chip
::Chip(const QColor &color,
int x,
int y,
const QString &tipo,
const qreal
&ancho,
const qreal
&alto,
const QPixmap &pixmap
){
this->x = x;
this->y = y;
this->color = color;
this->tipo = tipo;
this->ancho = ancho;
this->alto = alto;
this->pixmap = pixmap;
setZValue(1);
setFlags(ItemIsSelectable);
setAcceptsHoverEvents(true);
startTimer(5000);
}
...
{
...
}
#include "chip.h"
#include "loc.h"
#include <QtGui>
#include <QtSql>
loc_position_t loc_pos;
Chip::Chip(const QColor &color, int x, int y, const QString &tipo, const qreal &ancho, const qreal &alto, const QPixmap &pixmap)
{
this->x = x;
this->y = y;
this->color = color;
this->tipo = tipo;
this->ancho = ancho;
this->alto = alto;
this->pixmap = pixmap;
setZValue(1);
setFlags(ItemIsSelectable);
setAcceptsHoverEvents(true);
startTimer(5000);
}
...
void Chip::timerEvent(QTimerEvent *)
{
...
}
To copy to clipboard, switch view to plain text mode
Now my problem is I get the error:
:: === chip2, Debug ===
chip.cpp:24: error: `startTimer' undeclared (first use this function)
...
:: === chip2, Debug ===
chip.cpp:24: error: `startTimer' undeclared (first use this function)
...
To copy to clipboard, switch view to plain text mode
Why is that? I have rerun qmake and the Q_OBJECT macro is the .h file. I cannot find why the error. Can anyone help?
Bookmarks