Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, August 2007
simple QTransform issue with QGraphicsPixmapItem


Message 1 in thread

I am trying to rotate one QGraphicsPixmapItem (one) around its own
center Y-Axis. But I can't figure out how I should do that. The
QGraphicsPixmapItem is located in a QGraphicsScene.

This is the relevant code, the expected result and the actual result:

// code, called by QTimeLine frameChanged(int frame)

    QTransform *t = new QTransform();
    int cX = view->width()/2;
    int cY = view->height()/2;
    t->translate(cX, cY);
    t->rotate(frame, Qt::YAxis);
    t->translate(-cX, -cY);
    one->setTransform(*t);

// expected result:

    QGraphicsItem one should rotate around its own center Y axis.

// result:

    QGraphicsItem one rotates (and scales too?) around the
    Y-axis to the left of the QGraphicsItem instead of around its own center.

-- 
 [ signature omitted ] 

Message 2 in thread

On 07/08/2007, at 16.33, Wesley S. wrote:

> I am trying to rotate one QGraphicsPixmapItem (one) around its own
> center Y-Axis. But I can't figure out how I should do that. The
> QGraphicsPixmapItem is located in a QGraphicsScene.
>
> This is the relevant code, the expected result and the actual result:
>
> // code, called by QTimeLine frameChanged(int frame)
>
>     QTransform *t = new QTransform();
>     int cX = view->width()/2;
>     int cY = view->height()/2;
>     t->translate(cX, cY);
>     t->rotate(frame, Qt::YAxis);
>     t->translate(-cX, -cY);
>     one->setTransform(*t);
>
> // expected result:
>
>     QGraphicsItem one should rotate around its own center Y axis.
>
> // result:
>
>     QGraphicsItem one rotates (and scales too?) around the
>     Y-axis to the left of the QGraphicsItem instead of around its  
> own center.
>

I've been bitten by this one myself. As I understand it the order  
doesn't matter.
In order to get your (and my) expected result I think you need to  
multiply transformations.

t = move_backTransform * rotateTransform * moveTransform;

Frederik

-- 
 [ signature omitted ] 

Message 3 in thread

2007/8/7, Frederik Juul Christiani <juul@xxxxxxxxxxxxxxxxxxxxx>:
>
> On 07/08/2007, at 16.33, Wesley S. wrote:
>
> I am trying to rotate one QGraphicsPixmapItem (one) around its own
> center Y-Axis. But I can't figure out how I should do that. The
> QGraphicsPixmapItem is located in a QGraphicsScene.
>
> This is the relevant code, the expected result and the actual result:
>
> // code, called by QTimeLine frameChanged(int frame)
>
>     QTransform *t = new QTransform();
>     int cX = view->width()/2;
>     int cY = view->height()/2;
>     t->translate(cX, cY);
>     t->rotate(frame, Qt::YAxis);
>     t->translate(-cX, -cY);
>     one->setTransform(*t);
>
> // expected result:
>
>     QGraphicsItem one should rotate around its own center Y axis.
>
> // result:
>
>     QGraphicsItem one rotates (and scales too?) around the
>     Y-axis to the left of the QGraphicsItem instead of around its own
> center.
>
>
> I've been bitten by this one myself. As I understand it the order doesn't
> matter.
> In order to get your (and my) expected result I think you need to multiply
> transformations.
>
> t = move_backTransform * rotateTransform * moveTransform;

I don't understand how I should do that in Qt/C++

-- 
 [ signature omitted ] 

Message 4 in thread

> > I've been bitten by this one myself. As I understand it the order
> doesn't
> > matter.
> > In order to get your (and my) expected result I think you need to
> multiply
> > transformations.
> >
> > t = move_backTransform * rotateTransform * moveTransform;
> 
> I don't understand how I should do that in Qt/C++

http://doc.trolltech.com/4.3/qtransform.html#operator-2a

If you're using the translate, rotate or scale methods, you're just
setting properties of one transformation. The order in which you do that
doesn't matter.

If you want to first translate, then rotate, then translate again,
you'll have to create 3 seperate QTransform objects, and combine them
with the * operator.

Cheers,
Peter

--
 [ signature omitted ]