hi,
i have some ballons which should come one by one with a time gap.so that i can get random character different as ballon text.how can i do that?
please help me
regards,
hema
Printable View
hi,
i have some ballons which should come one by one with a time gap.so that i can get random character different as ballon text.how can i do that?
please help me
regards,
hema
I guess you mean tool tip by balloons. You could use QTimer to do so, start a QTimer, and in the slot connected to QTimer show the balloons as required.
Code:
connect(timer, SIGNAL(timeout), this, SLOT(createBalloon)); timer->start(); void createBalloon(void) { //create / show balloon. }
I hope, you know how to use signals and slots
hi sir,
thanks for ur reply.
the solution giving error.
main.cpp-------------where i call ballon.cpp
Code:
#include<QtGui> #include"ballon.h" int main(int argc,char **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.setBackgroundBrush(Qt::yellow); for(int i=1;i<=3;i++) { for(int j=1;j<=9;j++) { if(i*j<=26) { } } } //view.setMaximumSize(600,600); view.show(); QTimer timer; 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); }
ballon.cpp -----------------
Code:
#include "ballon.h" #include<QFont> #include<QPainter> #include<QGraphicsItemAnimation> #include<QGraphicsScene> #include<QGraphicsSceneMouseEvent> { } { _mtext=text; } { return _mtext; } { painter->setBrush(Qt::red); painter->drawEllipse(boundingRect()); painter->drawText(boundingRect().center(),_mtext); } { } 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); }
Error-----------invalid use of this in non member function
how can i set time interval please how can i insert signal from main.cpp to ballon constructor
Note my earlier replyYou get an error because you don't know how to use signals & slots (Don't feel bad). I will try to explain a bit, you should be reading a good book or Qt Documentation at-least.Quote:
Originally Posted by Santosh Reddy
Following points are what you missed
- main() is a global function, it does not have a object instance of itself, so you cannot use this pointer in main() (it's basic C++, nothing to do with Qt), this is very reason you have an error.
- A slot has to a member function of a class which is either directly or indirectly derived from a QObject, i.e SLOT cannot be a global function (which is a problem in you case)
- You are creating 27 (3 x 9) timers, you should be creating only one timer, and each time the timer slot is called then create a balloon.
sir,
i know that 'this' can not be used in main function.
my app is to produce 26 ballons with A-Z as text . ballon,GraphicsItem should be viewed in GraphicsScene with a time gap.
how can i achieve this?
i have to call ballon constuctor with random character as input in main.cpp.
regards,
hema
Ok, there are many ways, i just give one example to do so. Refer the sample example, I tried to create from your inputs, check it out