Results 1 to 4 of 4

Thread: drawing points on canvas after a time period

  1. #1
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default drawing points on canvas after a time period

    hello everybody,
    I am currently using qt3.3.4.
    here is a piece code i am presenting for help. It is supposed to put
    points on canvas after a interval. Co-ordinate point are store in a 2d
    matrix a[][].canvas is object refrence to QCanvas class .
    Qt Code:
    1. void addPoint()
    2. {
    3. QPixmap bck=canvas.backGround();
    4. QPixmap *tpix=new QPixmap(canvas.width(),canvas.height());
    5. QRect r(0,0,canvas.width(),canvas.height());
    6. QPoint pt(0,0);
    7. p.begin(tpix);
    8. for (int i=0; i<10;i++)
    9. for(int j=0; j<10; j++)
    10. {
    11. p.fillRect(0,0,canvas.width(),canvas.height(),Qt::white);
    12. p.setPen(Qt::red);
    13. p.drawEllipse(a[i][j],a[i][j],3,3);
    14. bitblt(&bck,pt,tpix,r,Qt::AndROP);
    15. canvas.setBackGround(bck);
    16. sleep(1);
    17. }
    18. p.end;
    19. }
    To copy to clipboard, switch view to plain text mode 
    Here addPoint is a slot connected to menu item.Matrix a is being filled through a fifo.
    but this code is printing line in one go only after waiting for some time.
    What iwant is i can view plotting of each point aftera interval( here i put
    1 in sleep) ; Someone advised me using Qtimer but souldn't find exact way.

    I am thinking of creating a thread which will do the reading from fifo and main application will do the gui handling. Can i use pthread library inside qt. I haven't used QThread earlier. Also can i create a thread from inside a slot.
    Any help will be appreciable
    regards
    nitin
    Last edited by wysota; 12th May 2006 at 13:13. Reason: Added [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: drawing points on canvas after a time period

    Quote Originally Posted by quickNitin
    What iwant is i can view plotting of each point aftera interval( here i put 1 in sleep) ;
    QCanvas can animate objects all by itself. All you need is a QTimer connected to QCanvas::advance() and a class derived from QCanvasItem that will draw your object.

    I am thinking of creating a thread which will do the reading from fifo and main application will do the gui handling. Can i use pthread library inside qt. I haven't used QThread earlier. Also can i create a thread from inside a slot.
    QThread is much easier to use (you just have to subclass it and reimplement the run() method) and you can create it anywhere you want, just remember that you can't send signals between threads --- you must use custom events or some other mechanism.

    http://doc.trolltech.com/3.3/threads.html

    PS. Next time, please, don't ask two unrelated questions in a single thread --- create two threads instead.

  3. The following user says thank you to jacek for this useful post:

    quickNitin (12th May 2006)

  4. #3
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: drawing points on canvas after a time period

    thanks for answering
    But QCanvas::advance() is or objectwhich are animated , i mean have some velocity set for them. I my case i have simple points acting as center for QCanvasEllipse. Current posted code is drawing but not after fixed time interval.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: drawing points on canvas after a time period

    Quote Originally Posted by quickNitin
    thanks for answering
    But QCanvas::advance() is or objectwhich are animated , i mean have some velocity set for them. I my case i have simple points acting as center for QCanvasEllipse.
    Then create a slot connected to QTimer::timeout() and create/show next QCanvasEllipse in it.

    Quote Originally Posted by quickNitin
    Current posted code is drawing but not after fixed time interval.
    Your current code is wrong, because sleep() blocks the event loop and QCanvas can't redraw itself.

  6. The following user says thank you to jacek for this useful post:

    quickNitin (12th May 2006)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.