jeff28
16th August 2012, 09:36
I am trying to make my own SVGGenerator.
here is my displaywidget.h:
#ifndef DISPLAYWIDGET_H
#define DISPLAYWIDGET_H
#include <QHash>
#include <QWidget>
class DisplayWidget : public QWidget
{
Q_OBJECT
public:
enum Shape { BStar = 0, RStar = 1 };
enum Background { BBackground = 0, CBackground = 1, PBackground = 2 };
DisplayWidget(QWidget *parent = 0);
void paint(QPainter &painter);
public slots:
void setBackground(Background background);
void setShape(Shape shape);
protected:
void paintEvent(QPaintEvent *event);
private:
Background background;
Shape shape;
QHash<Shape,QPainterPath> shapeMap;
};
#endif // DISPLAYWIDGET_H
here is my displaywidget.cpp:
#include <QtGui>
#include "displaywidget.h"
DisplayWidget::DisplayWidget(QWidget *parent)
: QWidget(parent)
{
QPainterPath BStar;
QPainterPath RStar;
QFile file(":SVGGenerator/files/*.svg");
file.open(QFile::ReadOnly);
QDataStream stream(&file);
stream >> RStar >> BStar;
file.close();
shapeMap[RStar] = RStar; // no match for 'operator[]' in '((DisplayWidget*)this)->DisplayWidget::shapeMap[RStar]'
shapeMap[BStar] = BStar; // no match for 'operator[]' in '((DisplayWidget*)this)->DisplayWidget::shapeMap[BStar]'
background = BBackground;
shape = BStar; // cannot convert 'QPainterPath' to 'DisplayWidget::Shape' in assignment
}
void DisplayWidget::paintEvent(QPaintEvent * /* event */)
{
QPainter painter;
painter.begin(this);
painter.setRenderHint(QPainter::Antialiasing);
paint(painter);
painter.end();
}
void DisplayWidget::paint(QPainter &painter)
{
painter.setClipRect(QRect(0, 0, 200, 200));
painter.setPen(Qt::NoPen);
painter.setPen(Qt::black);
painter.translate(100, 100);
painter.drawPath(shapeMap[shape]);
}
void DisplayWidget::setBackground(Background background)
{
this->background = background;
update();
}
void DisplayWidget::setShape(Shape shape)
{
this->shape = shape;
update();
}
when I try to run this I get the commented errors on my .cpp file. I added all of my .svg files to every file in my project but still I have these errors. Can somebody help me?
here is my displaywidget.h:
#ifndef DISPLAYWIDGET_H
#define DISPLAYWIDGET_H
#include <QHash>
#include <QWidget>
class DisplayWidget : public QWidget
{
Q_OBJECT
public:
enum Shape { BStar = 0, RStar = 1 };
enum Background { BBackground = 0, CBackground = 1, PBackground = 2 };
DisplayWidget(QWidget *parent = 0);
void paint(QPainter &painter);
public slots:
void setBackground(Background background);
void setShape(Shape shape);
protected:
void paintEvent(QPaintEvent *event);
private:
Background background;
Shape shape;
QHash<Shape,QPainterPath> shapeMap;
};
#endif // DISPLAYWIDGET_H
here is my displaywidget.cpp:
#include <QtGui>
#include "displaywidget.h"
DisplayWidget::DisplayWidget(QWidget *parent)
: QWidget(parent)
{
QPainterPath BStar;
QPainterPath RStar;
QFile file(":SVGGenerator/files/*.svg");
file.open(QFile::ReadOnly);
QDataStream stream(&file);
stream >> RStar >> BStar;
file.close();
shapeMap[RStar] = RStar; // no match for 'operator[]' in '((DisplayWidget*)this)->DisplayWidget::shapeMap[RStar]'
shapeMap[BStar] = BStar; // no match for 'operator[]' in '((DisplayWidget*)this)->DisplayWidget::shapeMap[BStar]'
background = BBackground;
shape = BStar; // cannot convert 'QPainterPath' to 'DisplayWidget::Shape' in assignment
}
void DisplayWidget::paintEvent(QPaintEvent * /* event */)
{
QPainter painter;
painter.begin(this);
painter.setRenderHint(QPainter::Antialiasing);
paint(painter);
painter.end();
}
void DisplayWidget::paint(QPainter &painter)
{
painter.setClipRect(QRect(0, 0, 200, 200));
painter.setPen(Qt::NoPen);
painter.setPen(Qt::black);
painter.translate(100, 100);
painter.drawPath(shapeMap[shape]);
}
void DisplayWidget::setBackground(Background background)
{
this->background = background;
update();
}
void DisplayWidget::setShape(Shape shape)
{
this->shape = shape;
update();
}
when I try to run this I get the commented errors on my .cpp file. I added all of my .svg files to every file in my project but still I have these errors. Can somebody help me?