PDA

View Full Version : Best Qt class for a dynamic color grid



josiah42
7th January 2009, 18:38
I'm working on porting an application I wrote in OpenGL (glut) to Qt. I'm very happy with what I've seen of Qt so far. There seems to be many ways that I can do this and I'll be using this project for years, so I'm looking for some expert advice on what the Best way to do it would be.

I have a data visualization that is a grid of squares, each of which are assigned a color. Basically, I have a grid of pixels, but they aren't always 1:1 with screen pixels. I display each square in the order that you would display pixels in an image, starting at upper left, moving to the right until I reach the width at which point I wrap to the next line. The catch is that the width is adjustable by the user so the "pixels" can migrate around on the screen. The visualization is rectangular, but the dimensions change based on user input.

Design priorities:
1) Layout can be easily changed
2) Runs in real-time even with 100,000+ "pixels" on the screen
3) Should be able to smoothly zoom in an out (basically scale the image).
4) Ability to easily select 1 "pixel" using mouse input.

The ability to select 1 pixel with a mouse is last on the list because zooming in/out and changing the width are used >100 times more often. If need be I could capture what screen pixel was clicked on and do the math to convert that to data points myself.

I've been looking at the Qt example Graphic View > Diagram Scene as a good starting point for the kind of interface I'm shooting for. I can see using Bitmap, QPixelMap, a group of QGraphicsPolygonItem or several others. I'll probably implement my own class that either inherits or contains a Qt class. Thanks for the advice. Making the right decision here will make a big difference to me.

wysota
7th January 2009, 19:04
Is there a reason to leave OpenGL behind and go for raster graphics? If not then you can use OpenGL with Qt as well.

josiah42
7th January 2009, 19:17
Is there a reason to leave OpenGL behind and go for raster graphics? If not then you can use OpenGL with Qt as well.
OpenGL compatibility is one of the reasons I picked Qt. 95% of all I do in this program is 2D though so my thought was that blitting pixels onto the screen would be much faster especially for very large datasets. My current OpenGL implementation simply treats each pixels and a square polygon with a solid color. This was easy to program but it becomes brain dead slow when I have 1 million polygons on the screen. I was considering simply writing a texture to a spot in memory and then having a single large rectangular polygon that gets texture mapped. While I'm making these improvements, I figured it would be a good time to switch to Qt.

I am thinking the Qt version of what I just described would be to have a QGraphicsPolygonItem painted with a QBrush constructed with a QPixelMap (or Bitmap?) to basically texture map the thing on. I will still want to do some 3D stuff in the future so I'm planning on having an OpenGL window but I was thinking that utilizing the Qt 2D graphics would be useful for my primary goal.

wysota
7th January 2009, 20:13
With Qt you can freely combine 2D and 3D graphics, even inside a single widget.