hi,
i want to add number of ballons(GraphicsItem) into graphicsScene depending upon the position in main.cpp given.
main.cpp
#include<QtGui>
#include"ballon.h"
int main(int argc,char **argv)
{
scene.setSceneRect(0,0,300,300);
scene.addItem(rectItem);
scene.setBackgroundBrush(Qt::yellow);
for(int i=0;i<5;i++)
{
Ballon *ball=new Ballon("H");
ball->setPos(200,200);
scene.addPath(ball->shape());
}
view.
setRenderHint(QPainter::Antialiasing);
view.
setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
view.show();
return app.exec();
}
#include<QtGui>
#include"ballon.h"
int main(int argc,char **argv)
{
QApplication app(argc,argv);
QGraphicsScene scene;
scene.setSceneRect(0,0,300,300);
QGraphicsRectItem *rectItem=new QGraphicsRectItem(0,0,300,30);
scene.addItem(rectItem);
QGraphicsTextItem *textItem=scene.addText("After / Before",QFont("",18,QFont::Bold));
scene.setBackgroundBrush(Qt::yellow);
scene.setItemIndexMethod(QGraphicsScene::NoIndex);
for(int i=0;i<5;i++)
{
Ballon *ball=new Ballon("H");
ball->setPos(200,200);
scene.addPath(ball->shape());
}
QGraphicsView view(&scene);
view.setRenderHint(QPainter::Antialiasing);
view.setCacheMode(QGraphicsView::CacheBackground);
view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
ballon.cpp
#include "ballon.h"
#include<QFont>
Ballon
::Ballon(QString text
): _mtext
(text
){
setPos(270,270);
}
{
_mtext=text;
}
{
return _mtext;
}
{
}
{
path.addEllipse(boundingRect());
return path;
}
QRectF Ballon
::boundingRect() const {
}
#include "ballon.h"
#include<QFont>
Ballon::Ballon(QString text): _mtext(text)
{
setPos(270,270);
}
void Ballon::setText(QString text)
{
_mtext=text;
}
QString Ballon::getText()
{
return _mtext;
}
void Ballon::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
}
QPainterPath Ballon::shape() const
{
QPainterPath path;
path.addEllipse(boundingRect());
return path;
}
QRectF Ballon::boundingRect() const
{
return QRectF(40,40,30,30);
}
To copy to clipboard, switch view to plain text mode
ellipse is drawing at boundingRect dimensions but not at ball.setpos(200,200)
i went thru examples but i dont find where the mistake lies.
please help me
Bookmarks