Results 1 to 5 of 5

Thread: Qt Drawing 2d grid based maze

  1. #1
    Join Date
    Nov 2019
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Qt Drawing 2d grid based maze

    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.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,194
    Thanks
    237
    Thanked 668 Times in 658 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Qt Drawing 2d grid based maze

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jul 2008
    Posts
    416
    Thanks
    9
    Thanked 54 Times in 52 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt Drawing 2d grid based maze

    Another way would be to draw the walls as separate lines/rectangles.

    Ginsengelf

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,194
    Thanks
    237
    Thanked 668 Times in 658 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Qt Drawing 2d grid based maze

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Jul 2008
    Posts
    416
    Thanks
    9
    Thanked 54 Times in 52 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt Drawing 2d grid based maze

    Quote Originally Posted by d_stranz View Post
    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

Similar Threads

  1. [Solved] What's wrong with my grid drawing code?
    By enjoysmath in forum Qt Programming
    Replies: 0
    Last Post: 10th August 2015, 00:46
  2. Replies: 3
    Last Post: 2nd April 2012, 10:32
  3. Replies: 14
    Last Post: 7th December 2011, 04:57
  4. Drawing a grid
    By LevelFour in forum Newbie
    Replies: 1
    Last Post: 14th February 2010, 17:38
  5. drawing a grid
    By dreamer in forum Qt Programming
    Replies: 2
    Last Post: 27th April 2008, 10:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.