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

Qt-interest Archive, March 2007
rotate() help needed


Message 1 in thread

Ive been using QT a little over a year now and I still
wince whenever I have to deal with coordinate stuff if it
goes beyond a standard un-rotated un-tranlated item.  Im
currently using QT4.3 snapshots.

The Class:  I subclass QGraphicsRectItem to create a
bounding box.  Within my subclass I create other rect's,
texts, polys and lines etc.  I offset everything to get
the unrotated item to look the way I want it.  This works
fine.

My problem:  I need to rotate the item (and everything inside)
and keep it relatively centered when it rotates.  Here's some
psuedo code (brushes, pens, show etc now shown for brevity):

MyRect::MyRect(QRectF box, QGraphicsPathItem *gpi) :
	QGraphicsRectItem(box, gpi)
{
	// init other items	
	_line = new QGraphicLinesItem(QLineF(10,10,20,20),gpi));
	_line->setPos(box.x() + 10, box.y() + 10);
	_rect = new QGraphicsRectItem(QRectF(5,5,8,8));
	_rect->setPos(box.x() + 10, box.y() + 20);
	_text = new QGraphicsTextItem(QString("Text"), gpi));
	_rect->setPos(box.x() + 5, box.y() + 5);
	_poly = new QGraphicsPolygonItem(poly, gpi);
	_poly->setPos(box.x() + 15, box.y() + 15);
}

void
MyRect::setRotate(int rot)
{
	_line->rotate(rot);
	_rect->rotate(rot);
	_text->rotate(rot);
	_poly->rotate(rot);
}

What do I do to get it all rotated and centered?
Im pretty sure the best way to do it is to
use QMatrix, scale and rotate, but
Ive never been able to get it to work the way I want it
in the past.  Your help is appreciated.

Jeff



--
 [ signature omitted ] 

Message 2 in thread

Jeff,

Painter rotation are done about the origin point of the painter. Basically wherever 0,0 is.  What you want is to translate your painter's origin to the center, rotate there and translate back.

--Justin


-----Original Message-----

From:  jeep@xxxxxxxxx (Jeff Lacki)
Subj:  rotate() help needed
Date:  Fri Mar 9, 2007 7:21 pm
Size:  1K
To:  qt-interest@xxxxxxxxxxxxx


Ive been using QT a little over a year now and I still
wince whenever I have to deal with coordinate stuff if it
goes beyond a standard un-rotated un-tranlated item.  Im
currently using QT4.3 snapshots.

The Class:  I subclass QGraphicsRectItem to create a
bounding box.  Within my subclass I create other rect's,
texts, polys and lines etc.  I offset everything to get
the unrotated item to look the way I want it.  This works
fine.

My problem:  I need to rotate the item (and everything inside)
and keep it relatively centered when it rotates.  Here's some
psuedo code (brushes, pens, show etc now shown for brevity):

MyRect::MyRect(QRectF box, QGraphicsPathItem *gpi) :
	QGraphicsRectItem(box, gpi)
{
	// init other items	
	_line = new QGraphicLinesItem(QLineF(10,10,20,20),gpi));
	_line->setPos(box.x() + 10, box.y() + 10);
	_rect = new QGraphicsRectItem(QRectF(5,5,8,8));
	_rect->setPos(box.x() + 10, box.y() + 20);
	_text = new QGraphicsTextItem(QString("Text"), gpi));
	_rect->setPos(box.x() + 5, box.y() + 5);
	_poly = new QGraphicsPolygonItem(poly, gpi);
	_poly->setPos(box.x() + 15, box.y() + 15);
}

void
MyRect::setRotate(int rot)
{
	_line->rotate(rot);
	_rect->rotate(rot);
	_text->rotate(rot);
	_poly->rotate(rot);
}

What do I do to get it all rotated and centered?
Im pretty sure the best way to do it is to
use QMatrix, scale and rotate, but
Ive never been able to get it to work the way I want it
in the past.  Your help is appreciated.

Jeff



--
 [ signature omitted ] 

Message 3 in thread

Jeff,

Forgot to mention you want to draw while the painter is translated and refactor your offsets to be relative to the new centered 0,0 origin.

--Justin


-----Original Message-----

From:  Justin Noel <justin@xxxxxxx>
Subj:  Re: rotate() help needed
Date:  Sat Mar 10, 2007 12:52 pm
Size:  2K
To:  qt-interest@xxxxxxxxxxxxx

Jeff,

Painter rotation are done about the origin point of the painter. Basically wherever 0,0 is.  What you want is to translate your painter's origin to the center, rotate there and translate back.

--Justin


-----Original Message-----

From:  jeep@xxxxxxxxx (Jeff Lacki)
Subj:  rotate() help needed
Date:  Fri Mar 9, 2007 7:21 pm
Size:  1K
To:  qt-interest@xxxxxxxxxxxxx


Ive been using QT a little over a year now and I still
wince whenever I have to deal with coordinate stuff if it
goes beyond a standard un-rotated un-tranlated item.  Im
currently using QT4.3 snapshots.

The Class:  I subclass QGraphicsRectItem to create a
bounding box.  Within my subclass I create other rect's,
texts, polys and lines etc.  I offset everything to get
the unrotated item to look the way I want it.  This works
fine.

My problem:  I need to rotate the item (and everything inside)
and keep it relatively centered when it rotates.  Here's some
psuedo code (brushes, pens, show etc now shown for brevity):

MyRect::MyRect(QRectF box, QGraphicsPathItem *gpi) :
	QGraphicsRectItem(box, gpi)
{
	// init other items	
	_line = new QGraphicLinesItem(QLineF(10,10,20,20),gpi));
	_line->setPos(box.x() + 10, box.y() + 10);
	_rect = new QGraphicsRectItem(QRectF(5,5,8,8));
	_rect->setPos(box.x() + 10, box.y() + 20);
	_text = new QGraphicsTextItem(QString("Text"), gpi));
	_rect->setPos(box.x() + 5, box.y() + 5);
	_poly = new QGraphicsPolygonItem(poly, gpi);
	_poly->setPos(box.x() + 15, box.y() + 15);
}

void
MyRect::setRotate(int rot)
{
	_line->rotate(rot);
	_rect->rotate(rot);
	_text->rotate(rot);
	_poly->rotate(rot);
}

What do I do to get it all rotated and centered?
Im pretty sure the best way to do it is to
use QMatrix, scale and rotate, but
Ive never been able to get it to work the way I want it
in the past.  Your help is appreciated.

Jeff



--
 [ signature omitted ]