Perspective transformations on a QGraphicsView

Posted by Andreas Aardal Hanssen on March 1, 2007 · 7 comments

I don’t have much to say this time, just wanted to share a screenshot after I changed the 40000 Chips demo a bit. I replaced the single horizontal rotation-slider with three ones, each controlling one axis or rotation for the view. QTransform is really easy to use, and with some twiddling (thumb up, pointing finger straight and your index finger pointing to the left), you can get some pretty amazing effects.


QGraphicsView view(&scene);

QTransform transform;
transform.rotate(45, Qt::XAxis);
transform.rotate(22.5, Qt::YAxis);

view.setTransform(transform);
view.show();

Setting one on a QGraphicsView works well, but there are still some rough edges that’ll get fixed pretty soon. Anyway, this is what it looks like (interaction works just as well).


Transform - small

QShare(this)

Possibly related posts:

  1. Qt + Box2D is easy!
  2. Qt 4.6.2 for Maemo 5 released

7 comments

1 wysota March 2, 2007 at 9:41 am
 

Does it use OpenGL hardware acceleration for QGLWidget viewport?

2 Andreas March 2, 2007 at 11:28 am
 

Hi, Wysota. QGLWidget uses hardware acceleration if your drivers support it, this screenshot shows that OpenGL is enabled on all views, so it uses QGLWidget for all viewports. But as you can see from the top-left view, my driver doesn’t support samplebuffers, so antialiasing has no effect.

3 wysota March 2, 2007 at 11:55 am
 

No, no – I know QGLWidget uses hardware acceleration. I meant to ask if it uses OpenGL for QTransform effects.

4 Andreas March 5, 2007 at 10:08 am
 

QGLWidget uses OpenGL for everything.

5 Zandru March 6, 2007 at 2:28 pm
 

looks awesome :) i have an offtopic hint for you: if you use Alt-PrintScreen for your Screenshots, you don’t have to manually clip them ;-)

6 Chris March 6, 2007 at 4:50 pm
 

My problem with the current QMatrix/QGraphicsView is that I can’t scroll maps forever. Imagine a map of the earth and I scroll right, then I want to start seeing the portion of the map formally on the left.

For example,
http://mathworld.wolfram.com/CylindricalEquidistantProjection.html

If I scroll right on the map in the above link, I want to see Australia show up on the left. Is this possible with QTransform?

7 Andreas March 6, 2007 at 8:49 pm
 

Nope, QGraphicsView can’t do spherical projection. It just (4.3) got support for perspective transformations… I guess the more features we add, the more possibilities you see ;-) .

Comments on this entry are closed.

Previous post:

Next post: