QGraphicsView QSvgRenderer and OpenGl
Hey Guys,
basically i want to render multiple layered Svg on the Graphics card, in 20-50ms update rate.
For Testing and understanding this i wrote some Code.
It works, but not as i expexcted.
It looks not really antialized. Also it should be resizable at runtime.
Header of my Widgets i want to place inside the QGraphics View
Code:
#ifndef SVGWIDGET_H_
#define SVGWIDGET_H_
#include <qwidget.h>
#include <qsvgrenderer.h>
/*!
* @brief This class represents a little extension of the QWidget to display a svg as a backgroundimage.
*/
{
public:
/*!
*Constructor with given parent Widget
* @param parent is the parent widget
*/
~SvgWidget();
/*!
* Sets the background to be displayed and resizes the widget to the
* background's size.
* repaints the widget if background is changed
* @param backgroundPath the path to the svg for the background
*/
void
setUpBackgroundSvg
(QString backgroundPath
);
protected:
/*!
* Paints the background of the widget.
* @param pe
*/
void
private:
/*!
* Renderer for the background
*/
};
#endif /* SVGWIDGET_H_ */
source file of my little SvgWidget
Code:
#include <SvgWidget.h>
#include <qpainter.h>
#include <qlayout.h>
SvgWidget
::SvgWidget(QWidget * parent
) :{
}
SvgWidget::~SvgWidget()
{
}
void
SvgWidget
::setUpBackgroundSvg(QString backgroundPath
){
background_.load(backgroundPath);
this->resize(background_.defaultSize());
repaint();
}
void
{
if (background_.isValid())
{
background_.render(&painter);
}
}
Code:
#ifndef MYVIEW_H_
#define MYVIEW_H_
#include <qgraphicsview.h>
#include "SvgWidget.h"
{
Q_OBJECT
SvgWidget* widget;
public:
virtual
~MyView();
};
#endif /* MYVIEW_H_ */
Code:
#include "MyView.h"
#include <QGLWidget>
#include <qtimer.h>
{
widget = new SvgWidget(0);
widget->setUpBackgroundSvg(":/images/some.svg");
//some more layers will be set up here
scene()->addWidget(widget); //from here
setViewport(
update(); //to here
// if the code above is disabled, it looks better but is not rendered on the cpu right?
timer_->setInterval(20);
connect(timer_, SIGNAL(timeout()), this, SLOT(repaint()));
timer_->start();
}
MyView::~MyView()
{
}
main.cpp
Code:
#include <qapplication.h>
#include "MyView.h"
int
main(int argc, char *argv[])
{
MyView myView(0);
myView.repaint();
myView.show();
return app.exec();
}
I'm very Happy for all suggestions how to draw a Svg on the GPU.
Thank You!