class A: public QWidget{ friend class B; QList<B> list_B;/*...*/}class B{ friend class C; QList<C> list_C; /*...*/}class C{ /*...*/ }
class A: QGraphicsScene{ friend class B; QList<B> list_B;public: QGraphicsScene retA() { /*прокручиваем весь список*/ this->addItem( list_B.pop_back()); /* что-то еще делаем и возвращаем this*/ }/*...*/}class B: public QGraphicsItemGroup{ friend class C; QList<C> list_C;public: /*делаем подобную операцию, с добавлением элементов класса С в группу В*/ /*реализуем обязательные виртуальные функции [i]boundingRect[/i] and [i]paint[/i]*/ }class C: public QGraphicsItem{ /*реализуем обязательные виртуальные функции [i]boundingRect[/i] and [i]paint[/i]*/}
C++ (Qt)class A{public: A() {} void virtual somePaint() { /* realization */}}; class B : public A{public: B() {} void somePaint() { /* B-specific realization */}} class C : public A{public: C() {} void somePaint() { /* C-specific realization */}}
C++ (Qt)class A{public: A() {} void virtual somePaint() = 0;};
C++ (Qt)#ifndef TRACK_H#define TRACK_H #include <QtGui> class Track : public QWidget{ Q_OBJECTpublic: Track(QWidget *parent = 0); QSize sizeHint() const; void paintEvent(QPaintEvent *);};#endif // TRACK_H
C++ (Qt)#include "track.h"#include "note.h"Track::Track(QWidget *parent) : QWidget(parent){ setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum); } void Track::paintEvent(QPaintEvent *e){ QPainter painter; painter.begin(this); painter.drawLine(0,0,100,500); painter.end(); Note n; n.paint(); /* Note *n = new Note(); n->paint(); */} QSize Track::sizeHint() const{ return QSize(900,76);}
C++ (Qt)#ifndef NOTE_H#define NOTE_H#include "track.h"class Note : public Track{ Q_OBJECTpublic: Note(QWidget *parent = 0): Track(parent) {} void paint() { QPainter pa; pa.begin(this); pa.drawLine(0,0,900,900); pa.end(); } void paintEvent(QPaintEvent *) {} QSize sizeHint() const { return QSize(900,76); }};#endif // NOTE_H
QPainter::begin: Paint device returned engine == 0, type: 1QPainter::end: Painter not active, aborted