Important: Please read the Qt Code of Conduct -

Which base should I use for my graphics widget?

  • I am working on a project that is based on tiles of at least two shapes. (Currently just hexes and squares). The shapes will not be mixed but which shape is used is dependent on the source file that provides the basic map data. I need to be able to quickly draw the entire surface that can have as many as 30,000 squares or hexes plus a sprite for each one (usually numerical text but sometimes arrows and other custom drawn, informational icons) every time the data for the picture or the zoom (size of each tile) is updated (which happens often). The surface needs to be scrollable as well (though I can probably plop a QBitmap on a scrollable surface if necessary). I also need the ability to quickly export the resulting image to a bmp, png, or jpeg file.

    I know there are at least four picture formats: QBitmap, QPixmap, QImage, and QPicture as well as the QGraphicsView class which I discovered while looking up information on drawing hexes. Currently QGraphicsView seems the most convenient but since it seems to manage objects that are part of the picture, I am wondering if this is the best solution since each tile will always have the same relative coordinate on the screen (no animation) and in my experience containers that manage objects are slower when it comes to rendering. My .NET version of the same project simply draws the shapes directly onto the graphics surface which has worked pretty well with squares and I assume could do as well for hexes. My converting to Qt is mainly because the project is ultimately going to need to be in C++ anyway so I figured that with the modifications I need to do to handle a new kind of map I might as well incorporate it into a C++ version and do the translation now. Hence my selection of Qt.

    Bottom line... my basic question is this. Which class should I base the widget on?

  • Hi,

    the Graphics View Framework supports natively operations like zooming, scrolling, rotating and so on. Is also optimized to handle and to show a huge number of elements.

    Have a look to the examples to see what is possible to do.

    Bottom line... my basic question is this. Which class should I base the widget on?

    If you use the Graphic View Framework the widget is QGraphicsView

Log in to reply