augusbas
23rd June 2011, 10:15
Hi all,
I have sub-classed graphics view and i have implemented "draw foreground" function ..I need to draw ellipse's on the view foreground...Provided my code for reference .
Header File:
#include <QGraphicsView>
class MyView: public QGraphicsView
{
Q_OBJECT
public:
MyView(QWidget *parent = 0);
protected:
void drawForeground(QPainter * painter, const QRectF & rect);
};
Source File:
#include <QtGui>
#include <QX11Info>
#include "graphics.h"
MyView::MyView(QWidget *parent) : QGraphicsView(parent)
{
//--- Graphics View Properties
this->resize ( 768, 768 );
this->setStyleSheet("background-image: url(/aegean-120km.png)");
/*
QGraphicsScene scene;
scene.setSceneRect (0,0, 768, 768 );
this->setScene ( &scene );
*/
QColor color(Qt::yellow);
QBrush brush(color, Qt::SolidPattern);
this->setForegroundBrush(brush);
this->show();
}
void MyView::drawForeground(QPainter * painter, const QRectF & rect)
{
QColor color1(156, 189, 176,254);
painter->setPen(Qt::lightGray);
int x,y,w,h,i;
double centre_x=384, centre_y=384;
double step_size=38.5;
for(i=1;i<=20 ;i++)
{
x = centre_x - step_size * i ;
y = centre_y - step_size * i ;
w=h=step_size * i * 2;
painter->drawEllipse(x,y,w,h);
}
}
I didn't get any ellipse on the foreground ....By ref to manual Whether "draw foreground " function will be applicable only to QGraphicsScene ? how the draw foreground function will get called, automatically or any update mechanism need to be added in the code ...
Please advise..
I have sub-classed graphics view and i have implemented "draw foreground" function ..I need to draw ellipse's on the view foreground...Provided my code for reference .
Header File:
#include <QGraphicsView>
class MyView: public QGraphicsView
{
Q_OBJECT
public:
MyView(QWidget *parent = 0);
protected:
void drawForeground(QPainter * painter, const QRectF & rect);
};
Source File:
#include <QtGui>
#include <QX11Info>
#include "graphics.h"
MyView::MyView(QWidget *parent) : QGraphicsView(parent)
{
//--- Graphics View Properties
this->resize ( 768, 768 );
this->setStyleSheet("background-image: url(/aegean-120km.png)");
/*
QGraphicsScene scene;
scene.setSceneRect (0,0, 768, 768 );
this->setScene ( &scene );
*/
QColor color(Qt::yellow);
QBrush brush(color, Qt::SolidPattern);
this->setForegroundBrush(brush);
this->show();
}
void MyView::drawForeground(QPainter * painter, const QRectF & rect)
{
QColor color1(156, 189, 176,254);
painter->setPen(Qt::lightGray);
int x,y,w,h,i;
double centre_x=384, centre_y=384;
double step_size=38.5;
for(i=1;i<=20 ;i++)
{
x = centre_x - step_size * i ;
y = centre_y - step_size * i ;
w=h=step_size * i * 2;
painter->drawEllipse(x,y,w,h);
}
}
I didn't get any ellipse on the foreground ....By ref to manual Whether "draw foreground " function will be applicable only to QGraphicsScene ? how the draw foreground function will get called, automatically or any update mechanism need to be added in the code ...
Please advise..