I need to draw an Image and a couple of lines, using my sub-classed QGraphicsItem
Here is my code(header file)-
#ifndef LED_H
#define LED_H
#include <QtGui>
#include <QGraphicsItem>
class LED : public QGraphicsItem
{
public:
explicit LED();
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
private:
static QPixmap *led_on; //<--Problem
};
#endif // LED_H
Note- LED
will be added to QGraphicsScene
Now I don't know how to approach it(drawing image using QGraphicsItem), but decided to use a static QPixmap
, which shall be shared by all the instances of LED
class.
And in cpp file added this->
QPixmap* LED::led_on = new QPixmap(":/path");
But I am getting this error on build and run-
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Must construct a QApplication before a QPaintDevice
The program has unexpectedly finished.
Please tell me how to do it. (I am new to Qt)
Should I use QImage
or something else instead?