Results 1 to 4 of 4

Thread: QPolygon rotate

  1. #1
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QPolygon rotate

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QPolygon rotate

    You can rotate a QPolygon by QMatrix::map() more or less like this:
    Qt Code:
    1. QPolygon polygon;
    2. ..
    3. QMatrix matrix;
    4. matrix.rotate(45);
    5. polygon = matrix.map(polygon);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    xgoan (27th October 2006)

  4. #3
    Join Date
    Mar 2007
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPolygon rotate

    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);

    }

  5. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPolygon rotate


Similar Threads

  1. Rotate QLabel
    By shader76 in forum Newbie
    Replies: 9
    Last Post: 24th December 2007, 12:31
  2. GraphicsView rotate problem
    By forrestfsu in forum Qt Programming
    Replies: 7
    Last Post: 21st November 2007, 20:20
  3. QPainter rotate function
    By ir210 in forum Newbie
    Replies: 3
    Last Post: 17th January 2006, 04:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.