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 [qtclass
]QWidget[/qtclass
]{
Q_OBJECT
public:
enum Shape { BStar = 0, RStar = 1 };
enum Background { BBackground = 0, CBackground = 1, PBackground = 2 };
DisplayWidget
([qtclass
]QWidget[/qtclass
] *parent
= 0);
void paint
([qtclass
]QPainter[/qtclass
] &painter
);
public slots:
void setBackground(Background background);
void setShape(Shape shape);
protected:
void paintEvent
([qtclass
]QPaintEvent[/qtclass
] *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([qtclass
]QWidget[/qtclass
] *parent
){
[qtclass
]QFile[/qtclass
] file(":SVGGenerator/files/*.svg");
file.
open(QFile::ReadOnly);
stream >> RStar >> BStar;
file.close();
shapeMap[RStar] = RStar; [COLOR="#FF0000"]// no match for 'operator[]' in '((DisplayWidget*)this)->DisplayWidget::shapeMap[RStar]'[/COLOR]
shapeMap[BStar] = BStar;[COLOR="#FF0000"] // no match for 'operator[]' in '((DisplayWidget*)this)->DisplayWidget::shapeMap[BStar]'[/COLOR]
background = BBackground;
shape = BStar; [COLOR="#FF0000"]// cannot convert 'QPainterPath' to 'DisplayWidget::Shape' in assignment[/COLOR]
}
void DisplayWidget
::paintEvent([qtclass
]QPaintEvent[/qtclass
] * /* event */) {
painter.begin(this);
painter.
setRenderHint(QPainter::Antialiasing);
paint(painter);
painter.end();
}
void DisplayWidget
::paint([qtclass
]QPainter[/qtclass
] &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();
}
#ifndef DISPLAYWIDGET_H
#define DISPLAYWIDGET_H
#include <QHash>
#include <QWidget>
class DisplayWidget : public [qtclass]QWidget[/qtclass]
{
Q_OBJECT
public:
enum Shape { BStar = 0, RStar = 1 };
enum Background { BBackground = 0, CBackground = 1, PBackground = 2 };
DisplayWidget([qtclass]QWidget[/qtclass] *parent = 0);
void paint([qtclass]QPainter[/qtclass] &painter);
public slots:
void setBackground(Background background);
void setShape(Shape shape);
protected:
void paintEvent([qtclass]QPaintEvent[/qtclass] *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([qtclass]QWidget[/qtclass] *parent)
: QWidget(parent)
{
[qtclass]QPainterPath[/qtclass] BStar;
[qtclass]QPainterPath[/qtclass] RStar;
[qtclass]QFile[/qtclass] file(":SVGGenerator/files/*.svg");
file.open(QFile::ReadOnly);
[qtclass]QDataStream[/qtclass] stream(&file);
stream >> RStar >> BStar;
file.close();
shapeMap[RStar] = RStar; [COLOR="#FF0000"]// no match for 'operator[]' in '((DisplayWidget*)this)->DisplayWidget::shapeMap[RStar]'[/COLOR]
shapeMap[BStar] = BStar;[COLOR="#FF0000"] // no match for 'operator[]' in '((DisplayWidget*)this)->DisplayWidget::shapeMap[BStar]'[/COLOR]
background = BBackground;
shape = BStar; [COLOR="#FF0000"]// cannot convert 'QPainterPath' to 'DisplayWidget::Shape' in assignment[/COLOR]
}
void DisplayWidget::paintEvent([qtclass]QPaintEvent[/qtclass] * /* event */)
{
[qtclass]QPainter[/qtclass] painter;
painter.begin(this);
painter.setRenderHint(QPainter::Antialiasing);
paint(painter);
painter.end();
}
void DisplayWidget::paint([qtclass]QPainter[/qtclass] &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();
}
To copy to clipboard, switch view to plain text mode
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?
Bookmarks