Quote Originally Posted by jacek
Why do you create new widgets if Son is a widget too? Wouldn't it be enough to redraw Son?
But I don t want to create new ones ! Qt does ...
The architecture is :
I've got a class Bck1 and Bck2. In both classes I do some drawing with QPaintEvent (the 2 classes are Widgets).
I ve got then the class Mother with his Son.
And I want the Son to do some drawings in bot he Bck1 and Bck2.
My problem is : Son is not a Widget but he must inherit from QWidget to know where he must paint ?



Qt Code:
  1. #include <QWidget>
  2.  
  3. class Bck1: public QWidget
  4. {
  5. Q_OBJECT
  6.  
  7. public :
  8. Bck1(QWidget *parent = 0);
  9. ~Bck2();
  10. ...
  11. protected :
  12. void paintEvent(QPaintEvent *event);
  13. void mousePressEvent(QMouseEvent *event);
  14. void keyPressEvent(QKeyEvent *event);
  15. ...}
  16.  
  17. #include <QWidget>
  18.  
  19. class Bck2: public QWidget
  20. {
  21. Q_OBJECT
  22.  
  23. public :
  24. Bck2(QWidget *parent = 0);
  25. ~Bck2();
  26.  
  27. protected :
  28. void paintEvent(QPaintEvent *event);
  29. }
  30.  
  31.  
  32. #include <QWidget>
  33.  
  34.  
  35. class Mother: public QWidget
  36. {
  37. Q_OBJECT
  38.  
  39. public :
  40. Mother(QWidget *parent=0);
  41. virtual ~Mother();
  42. protected :
  43. virtual void paintEvent(QPaintEvent *event)=0;
  44.  
  45.  
  46. };
  47.  
  48. #include <QWidget>
  49.  
  50. class Son : public Mother
  51. {
  52.  
  53. Q_OBJECT
  54.  
  55. public :
  56. Son(.....);//do I need to put Son(QWidget *parent=0) ... ?????
  57. ~Son();
  58.  
  59. protected :
  60. void paintEvent(QPaintEvent *event);
  61. }
To copy to clipboard, switch view to plain text mode 

Does it seems ok ? I never know if I need to specify *parent or *parent=0, and if I need to put Qwidget *parent in the Son constructor ???