OGS
QGraphicsGrid.h
Go to the documentation of this file.
1
15#pragma once
16
17#include <QGraphicsItem>
18#include <QPen>
19
26class QGraphicsGrid : public QGraphicsItem
27{
28public:
29 QGraphicsGrid(QRectF rect,
30 int xCells,
31 int yCells,
32 QGraphicsItem* parent = nullptr);
33 QGraphicsGrid(int x,
34 int y,
35 int width,
36 int height,
37 int xCells,
38 int yCells,
39 QGraphicsItem* parent = nullptr);
40 QGraphicsGrid(QRectF rect,
41 int xCells,
42 int yCells,
43 bool ticks,
44 QPen pen,
45 QGraphicsItem* parent = nullptr);
46 QGraphicsGrid(int x,
47 int y,
48 int width,
49 int height,
50 int xCells,
51 int yCells,
52 bool ticks,
53 QPen pen,
54 QGraphicsItem* parent = nullptr);
55 ~QGraphicsGrid() override;
56
57 QRectF boundingRect() const override;
58 void paint(QPainter* painter,
59 const QStyleOptionGraphicsItem* option,
60 QWidget* widget) override;
61 void setNumberOfXCells(int xCells);
62 void setNumberOfYCells(int yCells);
63 void setRect(QRectF rect);
64 void setRect(int x, int y, int width, int height);
65
66private:
67 void initDefaultPens();
68
69 QPen _inside;
71 QRectF _bounds;
75};
A 2D cartesian grid as a QGraphicsItem.
void setRect(QRectF rect)
void setNumberOfYCells(int yCells)
Sets the number of cells in y direction.
~QGraphicsGrid() override
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Paints the grid.
void setNumberOfXCells(int xCells)
Sets the number of cells in x direction.
void initDefaultPens()
Defines the default pens.
QRectF boundingRect() const override
Returns the bounding rectangle of the grid.
QGraphicsGrid(QRectF rect, int xCells, int yCells, QGraphicsItem *parent=nullptr)