View Poll Results: Which is better one?

Voters
15. You may not vote on this poll
  • OpenGl

    6 40.00%
  • QPainter

    9 60.00%
Results 1 to 6 of 6

Thread: QPainter update()

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QPainter update()

    Hello There,

    i am developing an application to display 2D objects on screen with Qt4.2.2

    i am using QPainter class to show objects on the screen.
    The Requirement is to show small ellipse like objects. The Total number of objects is 500 and all these should be updated on the screen in micro seconds.

    i find the QPainter Class taking time of about 200 milliseconds on average to update atleast 300 plots.i use update() method to avoid flicker.

    should i need to use repaint class to update the screen()?if yes then how shall i avoid flicker.

    is there any other method other than repaint() or update() to display the objects?
    should i need to use QPainter Class or is there any other option to update the screen in microseconds?

    Thanks in Advance...

    Qt Code:
    1. QTimer *timer = new QTimer(this);
    2. connect(timer, SIGNAL(timeout()), this, SLOT(update()));
    3. timer->start(1);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void AnalogClock::paintEvent(QPaintEvent *)
    2. {
    3.  
    4. int side = qMin(width(), height());
    5. static int i = 0, j =0;
    6. static int flag = 1;
    7. int diameter;
    8. if(j<420)
    9. {
    10. j++;
    11. }
    12. else
    13. {
    14. printf("\nThe cleint exited");
    15. exit(0);
    16. }
    17. QPainter painter(this);
    18. painter.setRenderHint(QPainter::Antialiasing);
    19. side =qMin(width(),height() );
    20. painter.translate(side / 2, side / 2);
    21.  
    22. painter.drawRect(-side/2,-side/2,side,side);
    23.  
    24. painter.fillRect(QRect(-side/2,-side/2,side,side),QBrush(Qt::black));
    25.  
    26. static const QPointF points[4] = {
    27. QPointF(0,-side/2),
    28. QPointF(0,side/2),
    29. QPointF(-side/2,0),
    30. QPointF(side/2,0)
    31. };
    32. painter.setPen(QPen(Qt::green,1,Qt::DotLine));
    33. painter.drawLines(points,2);
    34. painter.setPen(QPen(Qt::green));
    35. painter.drawText(420,0,"60.0");
    36. painter.drawText(350,0,"50.0");
    37. painter.drawText(280,0,"40.0");
    38. painter.drawText(210,0,"30.0");
    39. painter.drawText(140,0,"20.0");
    40. painter.drawText(70,0,"10.0");
    41. painter.save();
    42. painter.restore();
    43. painter.setPen(QPen(Qt::green));
    44. for (diameter = 140; diameter<=840; diameter+=140)
    45. { painter.drawEllipse(QRect(-diameter / 2, -diameter / 2,
    46. diameter, diameter));
    47. }
    48. painter.setPen(QPen(Qt::black));
    49. for(i = 1; i <= 420; i= i+5)
    50. {
    51. if(flag == 1)
    52. {
    53. painter.setBrush(QBrush(Qt::red,Qt::SolidPattern));
    54. flag = 0;
    55. }
    56. else
    57. {
    58. painter.setBrush(QBrush(Qt::blue,Qt::SolidPattern));
    59. flag = 1;
    60. }
    61. painter.drawEllipse(QRect(i,j,10,10));
    62. painter.drawEllipse(QRect(-i,j,10,10));
    63. painter.drawEllipse(QRect(i,-j,10,10));
    64. painter.drawEllipse(QRect(-i,-j,10,10));
    65. }
    66. painter.end();
    67. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 21st March 2008 at 08:43. Reason: reformatted to look better

Similar Threads

  1. immediate update of QT object
    By db in forum Newbie
    Replies: 3
    Last Post: 14th August 2007, 12:25
  2. why there is no update on maximize? [QTableWidget]
    By macias in forum Qt Programming
    Replies: 2
    Last Post: 7th August 2007, 15:01
  3. How to update statusbar and tooltips
    By aamer4yu in forum Qt Programming
    Replies: 9
    Last Post: 21st December 2006, 12:38
  4. QSlider Update Problem
    By December in forum Qt Programming
    Replies: 4
    Last Post: 10th September 2006, 04:02
  5. Replies: 7
    Last Post: 20th March 2006, 20:03

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
  •  
Qt is a trademark of The Qt Company.