I know I can use simple constructor, but I used this constructor of QGraphicsRectItem: QGraphicsRectItem(qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent = 0)
and I want create a constructor like: QMyButton::QMyButton(qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent)
And I want to know why it doesn't work.
I use Qt Creator, so if I'm right qmake run ever when I build the project.
this is my qmybutton.h:
#ifndef QMYBUTTON_H
#define QMYBUTTON_H
#include <QGraphicsRectItem>
{
Q_OBJECT
public:
QMyButton();
QMyButton
(qreal x, qreal y, qreal w, qreal h,
QGraphicsItem *parent
= 0);
signals:
void myPressSignal();
protected:
};
#endif // QMYBUTTON_H
#ifndef QMYBUTTON_H
#define QMYBUTTON_H
#include <QGraphicsRectItem>
class QMyButton : public QObject, public QGraphicsRectItem
{
Q_OBJECT
public:
QMyButton();
QMyButton(qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent = 0);
signals:
void myPressSignal();
protected:
void mousePressEvent(QGraphicsSceneMouseEvent * event);
};
#endif // QMYBUTTON_H
To copy to clipboard, switch view to plain text mode
and this is my qmybutton.cpp:
#include "qmybutton.h"
QMyButton::QMyButton()
{
}
QMyButton
::QMyButton(qreal x, qreal y, qreal w, qreal h,
QGraphicsItem *parent
) :{
}
{
emit myPressSignal(); //Emits the signal
}
#include "qmybutton.h"
QMyButton::QMyButton()
{
}
QMyButton::QMyButton(qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent) :
QGraphicsRectItem(x, y, w, h, parent)
{
}
void QMyButton::mousePressEvent(QGraphicsSceneMouseEvent * event)
{
QGraphicsItem::mousePressEvent(event); //Call the ancertor
emit myPressSignal(); //Emits the signal
}
To copy to clipboard, switch view to plain text mode
Bookmarks