#include<QtGui>
#include"ballon.h"
int main(int argc,char **argv)
{
QString str
[]={"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z"};
scene.setSceneRect(0,0,600,600);
scene.addRect(0,10,600,30);
scene.
addText("After / Before",
QFont("",
18,
QFont::Bold));
scene.setBackgroundBrush(Qt::yellow);
for(int i=1;i<=3;i++)
{
for(int j=1;j<=9;j++)
{
if(i*j<=26)
{
QObject::connect(&interval,
SIGNAL(timeout
()),
this,
SLOT(createBallon
()));
}
}
}
view.
setRenderHint(QPainter::Antialiasing);
//view.setMaximumSize(600,600);
view.
setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
view.show();
QObject::connect(&timer,
SIGNAL(timeout
()),
&scene,
SLOT(advance
()));
timer.start(1000);
return app.exec();
}
void createBallon()
{
int random=qrand()%26;
Ballon *ball=new Ballon(str[random]);
ball->setPos(0+(j*60),550+(i*65));
scene.addItem(ball);
}
#include<QtGui>
#include"ballon.h"
int main(int argc,char **argv)
{
QApplication app(argc,argv);
QGraphicsScene scene;
QString str[]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
scene.setSceneRect(0,0,600,600);
scene.addRect(0,10,600,30);
scene.addText("After / Before",QFont("",18,QFont::Bold));
scene.setBackgroundBrush(Qt::yellow);
scene.setItemIndexMethod(QGraphicsScene::NoIndex);
for(int i=1;i<=3;i++)
{
for(int j=1;j<=9;j++)
{
if(i*j<=26)
{
QTimer *interval=new QTimer(1000,this);
QObject::connect(&interval,SIGNAL(timeout()),this,SLOT(createBallon()));
}
}
}
QGraphicsView view(&scene);
view.setRenderHint(QPainter::Antialiasing);
view.setCacheMode(QGraphicsView::CacheBackground);
//view.setMaximumSize(600,600);
view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
view.show();
QTimer timer;
QObject::connect(&timer,SIGNAL(timeout()),&scene,SLOT(advance()));
timer.start(1000);
return app.exec();
}
void createBallon()
{
int random=qrand()%26;
Ballon *ball=new Ballon(str[random]);
ball->setPos(0+(j*60),550+(i*65));
scene.addItem(ball);
}
To copy to clipboard, switch view to plain text mode
#include "ballon.h"
#include<QFont>
#include<QPainter>
#include<QGraphicsItemAnimation>
#include<QGraphicsScene>
#include<QGraphicsSceneMouseEvent>
Ballon
::Ballon(QString text
): _mtext
(text
){
}
{
_mtext=text;
}
{
return _mtext;
}
{
painter->setBrush(Qt::red);
painter->drawEllipse(boundingRect());
painter->drawText(boundingRect().center(),_mtext);
}
QRectF Ballon
::boundingRect() const {
}
void Ballon::advance(int phase)
{
Q_UNUSED(phase);
QList<QGraphicsItem*> items=scene()->items();
if(point.ry()<=40)
item->setPos(point.rx(),point.ry());
else
item->moveBy(0,-2);
}
}
{
scene()->removeItem(item);
}
#include "ballon.h"
#include<QFont>
#include<QPainter>
#include<QGraphicsItemAnimation>
#include<QGraphicsScene>
#include<QGraphicsSceneMouseEvent>
Ballon::Ballon(QString text): _mtext(text)
{
setFlag(QGraphicsItem::ItemIsMovable,TRUE);
}
void Ballon::setText(QString text)
{
_mtext=text;
}
QString Ballon::getText()
{
return _mtext;
}
void Ballon::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setBrush(Qt::red);
painter->drawEllipse(boundingRect());
painter->drawText(boundingRect().center(),_mtext);
}
QRectF Ballon::boundingRect() const
{
return QRectF(0,0,40,60);
}
void Ballon::advance(int phase)
{
Q_UNUSED(phase);
QList<QGraphicsItem*> items=scene()->items();
foreach (QGraphicsItem *item, items) {
QPointF point=item->pos();
if(point.ry()<=40)
item->setPos(point.rx(),point.ry());
else
item->moveBy(0,-2);
}
}
void Ballon::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem *item=scene()->mouseGrabberItem();
scene()->removeItem(item);
}
To copy to clipboard, switch view to plain text mode
Bookmarks