Вот один из вариантов.
C++ (Qt)
//.h
#ifndef MYSCENE_H
#define MYSCENE_H
#include <QGraphicsScene>
#include <QPainter>
#include <QtGui>
class myscene : public QGraphicsScene
{
public:
myscene();
QColor color; //номер цвета
protected:
virtual void drawItems (QPainter *painter, int numItems,
QGraphicsItem *items[],
const QStyleOptionGraphicsItem options[],
QWidget *widget);
#endif // MYSCENE_H
//.cpp
#include "myscene.h"
void myscene::drawItems(QPainter *painter, int numItems,QGraphicsItem *items[], const QStyleOptionGraphicsItem options[], QWidget *widget) {
for (int i = 0; i < numItems; ++i) {
// Draw the item
painter->save();
painter->setMatrix(items[i]->sceneMatrix(), true);
painter->setBrush(QBrush (color));
items[i]->paint(painter, &options[i], widget);
painter->restore();
}
}
Вываливается с ошибками компиляции
make: Entering directory `/home/pasha/work/QtQBasic'
/usr/bin/make -f Makefile.Debug
make[1]: Entering directory `/home/pasha/work/QtQBasic'
g++ -c -m64 -pipe -g -Wall -W -D_REENTRANT -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/opt/qtsdk-2009.01/qt/mkspecs/linux-g++-64 -I. -I/opt/qtsdk-2009.01/qt/include/QtCore -I/opt/qtsdk-2009.01/qt/include/QtGui -I/opt/qtsdk-2009.01/qt/include/QtOpenGL -I/opt/qtsdk-2009.01/qt/include -I/usr/X11R6/include -Idebug -I. -o debug/myscene.o myscene.cpp
myscene.cpp:3: ошибка: избыточная квалификация ‘myscene::’ элемента ‘drawItems’
myscene.cpp:3: ошибка: ‘void myscene::drawItems(QPainter*, int, QGraphicsItem**, const QStyleOptionGraphicsItem*, QWidget*)’ cannot be overloaded
myscene.h:16: ошибка: with ‘virtual void myscene::drawItems(QPainter*, int, QGraphicsItem**, const QStyleOptionGraphicsItem*, QWidget*)’
myscene.cpp:13: ошибка: expected `}' at end of input
myscene.cpp:13: ошибка: expected unqualified-id at end of input
make[1]: *** [debug/myscene.o] Ошибка 1
make[1]: Leaving directory `/home/pasha/work/QtQBasic'
make: *** [debug] Ошибка 2
make: Leaving directory `/home/pasha/work/QtQBasic'
Exited with code 2.
Error while building project QtQBasic
When executing build step 'Make'