PDA

View Full Version : Qt Drawing 2d grid based maze



thalorn
18th November 2019, 09:24
Hi, I need a little bit of advice. I work on a school project where robot goes through grid based maze (5x5) and then he sends coordinates of individual squares and obstacles in the squares to the database from which I read them and then I need to draw map of the maze. So my question is, what is the simplest way to make the grid. I thought the easy way would be to just draw 25 rectangles but I don't know if its possible to adjust the thickness of only one side of the rectangle.

d_stranz
18th November 2019, 19:30
A normal Qt rectangle uses the same pen (color and line width) for all sides. However, you can define your own data structure that contains the size and position of each rectangle in the maze, and as part of that data structure you can include the line width for each side (left, right, top, bottom). You would then draw the rectangle as a set of four calls to draw each individual side using the proper pen.

Ginsengelf
19th November 2019, 07:20
Another way would be to draw the walls as separate lines/rectangles.

Ginsengelf

d_stranz
20th November 2019, 00:51
Another way would be to draw the walls as separate lines/rectangles.

That's pretty much what I meant. Yet another way would be to use the Qt Graphics / View framework and define a new QAbstractGraphicsItem that culd draw each side of a rectangle with a different pen.

Ginsengelf
20th November 2019, 06:54
Yet another way would be to use the Qt Graphics / View framework and define a new QAbstractGraphicsItem that culd draw each side of a rectangle with a different pen.

That's what I thought you meant :)

Ginsengelf