Results 1 to 11 of 11

Thread: Refresh problem with QPaintEvent

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Refresh problem with QPaintEvent

    You are on you own
    Qt Code:
    1. #include <QtGui>
    2. #include <QApplication>
    3. #include "nightcharts.h"
    4.  
    5. class Dialog : public QDialog
    6. {
    7. Q_OBJECT
    8.  
    9. public:
    10.  
    11. explicit Dialog(QWidget *parent = 0)
    12. : QDialog(parent)
    13. , index(0)
    14. {
    15. this->setMinimumSize(800, 250);
    16. startTimer(1000);
    17. }
    18.  
    19. protected:
    20.  
    21. void paintEvent(QPaintEvent *event)
    22. {
    23. Q_UNUSED(event);
    24. QPainter painter(this);
    25. addGraphs(&painter, A[index], B[index], C[index]);
    26. }
    27.  
    28. private:
    29. static const int A[10];
    30. static const int B[10];
    31. static const int C[10];
    32. int index;
    33.  
    34. void addGraphs(QPainter *qp, int i, int j, int k)
    35. {
    36. Nightcharts chart1;
    37. chart1.setShadows(false);
    38. chart1.setType(Nightcharts::Pie);
    39. chart1.setLegendType(Nightcharts::Vertical);
    40. chart1.setCords(50, 50, 80, 80);
    41. chart1.addPiece("Item1", QColor(200,10,50), i);
    42. chart1.addPiece("Item2", Qt::green, j);
    43. chart1.addPiece("Item3", Qt::cyan, k);
    44. chart1.draw(qp);
    45. chart1.drawLegend(qp);
    46.  
    47. Nightcharts chart2;
    48. chart2.setShadows(false);
    49. chart2.setType(Nightcharts::Pie);
    50. chart2.setLegendType(Nightcharts::Vertical);
    51. chart2.setCords(300, 50, 80, 80);
    52. chart2.addPiece("Item2",Qt::green, j);
    53. chart2.addPiece("Item3",Qt::cyan,k);
    54. chart2.addPiece("Item4",Qt::yellow,i);
    55. chart2.draw(qp);
    56. chart2.drawLegend(qp);
    57.  
    58. Nightcharts chart3;
    59. chart3.setShadows(false);
    60. chart3.setType(Nightcharts::Pie);
    61. chart3.setLegendType(Nightcharts::Vertical);
    62. chart3.setCords(550, 50, 80, 80);
    63. chart3.addPiece("Item1",QColor(200,10,50), k);
    64. chart3.addPiece("Item3",Qt::cyan, i);
    65. chart3.addPiece("Item4",Qt::yellow, j);
    66. chart3.draw(qp);
    67. chart3.drawLegend(qp);
    68. }
    69.  
    70. void timerEvent(QTimerEvent *)
    71. {
    72. index++;
    73. index = index % 10;
    74. this->update();
    75. }
    76.  
    77. };
    78.  
    79. const int Dialog::A[] = { 10, 20, 30, 40, 50, 60, 70, 70, 50, 70 };
    80. const int Dialog::B[] = { 20, 30, 40, 50, 40, 30, 20, 10, 20, 30 };
    81. const int Dialog::C[] = { 70, 50, 30, 10, 10, 10, 10, 20, 30, 40 };
    82.  
    83. int main(int argc, char *argv[])
    84. {
    85. QApplication a(argc, argv);
    86.  
    87. Dialog dialog;
    88. dialog.exec();
    89.  
    90. return a.exec();
    91. }
    92.  
    93. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  2. The following user says thank you to Santosh Reddy for this useful post:

    rawfool (23rd April 2013)

Similar Threads

  1. QComboBox refresh problem
    By waynew in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2011, 12:30
  2. Replies: 2
    Last Post: 14th January 2011, 15:09
  3. QWidget Refresh Problem
    By MarkoSan in forum Qt Programming
    Replies: 2
    Last Post: 15th January 2008, 11:24
  4. QpaintEvent region problem with QPopupmenus
    By Qtkiller in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2007, 09:18
  5. QTableView refresh problem
    By tebessum in forum Qt Programming
    Replies: 3
    Last Post: 29th December 2006, 11:22

Tags for this Thread

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.