Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QPainter drawRects without draging a line behind



  • Hello, I am building a Snake game in QT 5.
    I am trying to draw the snakes body using a
    QVector<QRectF>. The class of the Snake is derived from QGraphicsItem so I am using paint method for drawing the object and head of the snake looks like
    QRectF(-20,-20,15,15). So I tried to add another object to the QVector after you collide with the food. The new QRectF was then
    QRectF(-35,-20,15,15) and it was drawn, but when you moved the snake to the right you were drawing a line.

    How do you make it so, that 2 rectangles are moving across the scene? Am I even in the right direction?

    Thanks for the help in advance.


  • Qt Champions 2019

    @Mquaza said in QPainter drawRects without draging a line behind:

    How do you make it so, that 2 rectangles are moving across the scene?

    I would say change their coordinates?