Valderman

QDMGraphicsScene.cpp

Apr 11th, 2022 (edited)
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include "GraphicsScene.hpp"
  2. #include <QtCore>
  3. #include <QtGui>
  4.  
  5. QDMGraphicsScene::QDMGraphicsScene(QWidget* pobj)
  6.     : QGraphicsScene(pobj)
  7. {
  8.     setSceneRect(-(scnWidth / 2), -(scnHeight / 2), scnWidth, scnHeight);
  9.     setBackgroundBrush(QColor("#393939"));
  10. }
  11.  
  12. // Virtual:
  13. void QDMGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect)
  14. {  
  15.     // Problem was here:
  16.     // Adding this and it'll work:
  17.     QGraphicsScene::drawBackground(painter, rect);
  18.  
  19.     QPen ppLight(QColor("#2f2f2f"));
  20.     ppLight.setWidth(1);
  21.  
  22.     int32_t left   = static_cast<int32_t>(rect.left());
  23.     int32_t right  = static_cast<int32_t>(rect.right());
  24.     int32_t top    = static_cast<int32_t>(rect.top());
  25.     int32_t bottom = static_cast<int32_t>(rect.bottom());
  26.  
  27.     int32_t first_left = left - (left % grdSize);
  28.  
  29.     QVector<QLine> gridVector;
  30.  
  31.     for (int32_t x = first_left; x < right; x += grdSize)
  32.     {
  33.         gridVector.push_back(QLine(x, top, x, bottom));
  34.     }
  35.  
  36.     painter->setPen(ppLight);
  37.     painter->drawLines(gridVector);
  38. }
  39.  
  40.  
Add Comment
Please, Sign In to add comment