Results 1 to 3 of 3

Thread: QTableView for hexagon map?

  1. #1
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QTableView for hexagon map?

    I'm writing a Qt4 application that plays a traditional "war game." These games are played on a map that is tessellated into hexagons, instead of squares like in chess.

    Now, if the game map is stored as a a huge graphic graphic image, the memory requirements are excessive. To reduce the memory usage, "tiles" are used. This exploits the fact that many of the game hexagons are identical. By analogy, if one wanted to store a chess board image, one would only have to store an image of a black square and a white square. The visible part of the chessboard could be drawn on the fly, then the playing pieces are drawn on top.

    Now, topographically, a hex grid is more or less equivalent to a square grid, if alternating columns are offset downward by half a square height. The pattern resembles bricks in a brick wall.

    I was going to implement the hex map display by using a graphic view with two scroll bars.

    However, the though occurs to me that it might be possible to subclass a QTableView to do the same thing. One would have to alter the painting and selection functions so alternate columns were offset.

    Would it make more sense to implement such a map with a QGraphicView, a QTableView, or some other widget?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView for hexagon map?

    I think QGraphicsView is definitely the way to go here.
    Creating a custom QTableView means not only rewriting the painting but also the widget interaction part, which could be a nightmare.

    What is wrong displaying the hexagons in a gview? You could still minimize memory usage by storing hexagon types as pixmaps and just use QGraphicsPixmapItem's with a clipping mask applied(a hexagon) to define its bounds.

    Regards

  3. #3
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView for hexagon map?

    Quote Originally Posted by marcel View Post
    Ihat is wrong displaying the hexagons in a gview? You could still minimize memory usage by storing hexagon types as pixmaps and just use QGraphicsPixmapItem's with a clipping mask applied(a hexagon) to define its bounds.
    Nothing is wrong with using a gview. But as I learn Qt I find it often has easier ways to do common tasks. So I just wanted to make sure that I wasn't doing things the hard way.

    I actually have hex map drawing code that I wrote for Microsoft Foundation Classes many years ago, it should be easy enough to adapt.

    I was bemused, however. The original program in MFC took me the better part of a week to get the user interface working. In PyQt4 with the Qt Designer, it took less than 15 minutes.

Similar Threads

  1. Set height of QTableView to fit exact number of rows.
    By Ben.Hines in forum Qt Programming
    Replies: 3
    Last Post: 17th January 2019, 01:49
  2. QTableView sorting
    By gabriels in forum Qt Programming
    Replies: 11
    Last Post: 6th October 2010, 17:13
  3. QTableView currentChanged <> selecting header
    By Everall in forum Qt Programming
    Replies: 4
    Last Post: 1st April 2009, 08:24
  4. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49

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.