void ItemSnake::paintEvent(QPaintEvent *){ RenderMode(direction);}void ItemSnake::RenderMode(Direction dir){ QPainter painter(this); painter.setPen(QPen(Qt::green,2,Qt::SolidLine)); if(dir == CommonDate::Down || dir == CommonDate::Up) { painter.drawLine(x() - offest, y() - offest, x() - offest, y() + offest); painter.drawLine(x() + offest, y() - offest, x() + offest, y() + offest); //painter.setBackground(QBrush(Qt::green)); painter.setBrush(Qt::green);// QPalette pal;// pal.setColor(this->backgroundRole(), Qt::green);// this->setPalette(pal);// this->setAutoFillBackground(true);// qDebug() << scene.sceneRect(); } if(dir == CommonDate::Right || dir == CommonDate::Left) { painter.drawLine(x() - offest, y() - offest, x() + offest, y() - offest); painter.drawLine(x() - offest, y() + offest, x() + offest, y() + offest); painter.setBackground(QBrush(Qt::green)); } switch (dir) { case CommonDate::TurnLeftUp : QPolygon poly; poly << QPoint(10,10) << QPoint(40,40) << QPoint(10,30) << QPoint(20,10); painter.setBrush(Qt::red); painter.drawPolygon(poly); break; default: //throw UnknownDirection; break; }}Объявление: class ItemSnake : public QWidget, public CommonDate{ Q_OBJECTpublic: explicit ItemSnake(QGraphicsScene& scene, CommonDate::Direction dir);private: CommonDate::Direction direction; //direction snake const int offest; QGraphicsScene& scene;protected: void RenderMode(CommonDate::Direction dir); //render item on the mode void paintEvent(QPaintEvent*);};class CommonDate //class, showing the direction of movement ItemSnake{protected: enum Direction { Right, Left, Up, Down, TurnRightUp, TurnLeftUp, TurnRightDown, TurnLeftDown, RightHead, LeftHead, UpHead, DownHead };};