PDA

View Full Version : QPolygon rotate



xgoan
26th October 2006, 15:25
Hi I'm doing a Widget that uses arrows, I have a arrow in a QPolygon and I want to clone and rotate it to create the other arrows.

Some help?

Thanks

jpn
26th October 2006, 15:34
You can rotate a QPolygon by QMatrix::map() more or less like this:


QPolygon polygon;
..
QMatrix matrix;
matrix.rotate(45);
polygon = matrix.map(polygon);

rohitjun
8th May 2007, 12:06
Hi,
I am doing one application in which, i wrote one class A to create different shapes of polygons. Then i wrote another class B for creating a special polygon which i have to attach with polygons of class A dynamically. Before i did somethinig similar but with QGraphicsItem class using setPos() function for attaching one polygon with another. But with QPolygon, it is working similar. Please suggest me some way.

Regards
Rohit

This is the constructor of class A

A::A(DiagramType diagramType, QMenu *contextMenu,
QGraphicsItem *parent, QGraphicsScene *scene)
: QGraphicsPolygonItem(parent, scene)
{
myDiagramType = diagramType;
myContextMenu = contextMenu;

QPainterPath path;

switch (myDiagramType) {

case StartEnd:
path.moveTo(200, 50);
path.arcTo(150, 0, 50, 50, 0, 90);
path.arcTo(50, 0, 50, 50, 90, 90);
path.arcTo(50, 50, 50, 50, 180, 90);
path.arcTo(150, 50, 50, 50, 270, 90);
path.lineTo(200, 25);
myPolygon = path.toFillPolygon();
break;

case Conditional:
myPolygon << QPointF(-100, 0) << QPointF(0, 100)
<< QPointF(100, 0) << QPointF(0, -100)
<< QPointF(-100, 0);
break;

case Step:
myPolygon << QPointF(-100, -100) << QPointF(100, -100)
<< QPointF(100, 100) << QPointF(-100, 100)
<< QPointF(-100, -100);

break;

default:
myPolygon << QPointF(-120, -80) << QPointF(-70, 80)
<< QPointF(120, 80) << QPointF(70, -80)
<< QPointF(-120, -80);
break;
}

anditem = new AndItem();

///// What code to write to attach andItem->myPolygon to myPolygon of this class.////


setPolygon(myPolygon);
setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);

}

marcel
8th May 2007, 12:18
You already posted here
http://www.qtcentre.org/forum/f-qt-programming-2/t-problem-in-attachig-two-polygons-6909.html