Results 1 to 16 of 16

Thread: How to reflect QGraphicsItem?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default How to reflect QGraphicsItem?

    I have a task to reflect one or more QGraphicsItems relatively to a line. And this operation should be performed correctly again and again to the mirrored items.
    I've read a lot about QTransform and affine transformations and realized that I need 1) rotate; 2) scale (1;-1) 3) translate..somewhere
    that's what I have now:
    Qt Code:
    1. QGraphicsLineItem* line = qgraphicsitem_cast<QGraphicsLineItem*>(curItem);
    2. double x1 = line->line().x1();
    3. double y1 = line->line().y1();
    4. double x2 = line->line().x2();
    5. double y2 = line->line().y2();
    6. double angle = atan((y2 - y1)/(x2 - x1));
    7. QMessageBox::warning(0, "Scribble", "angle "+QString::number(angle*180/acos(-1.0)));
    8. group->rotate(angle*180/acos(-1.0));
    9. group->scale(1,-1);
    10. group->rotate(-angle*180/acos(-1.0));
    11. foreach (QGraphicsItem* item,group->children())
    12. item->setTransform (group->transform(),true);
    13. destroyItemGroup(group);
    14. removeItem(line);
    15. delete line;
    16. curItem = NULL;
    To copy to clipboard, switch view to plain text mode 
    This is steps 1-2 as I don't know how to translate items correctly regardless of their pos() and previous mirror operations. At least the resulting angle of mirrored item seems to be right, but not after the second reflection
    "curItem" holds the line of the mirror (it's temporal and is erased after the operation), "group" of items to be reflected is created elsewhere.
    Thanks in advance for all your help. I attached the whole project (Qt 4.3.2, Visual Studio 2005 .vcproj, but without a .pro, sorry)
    Attached Files Attached Files

Similar Threads

  1. Disable default tab behaviour for a QGraphicsItem
    By nmather in forum Qt Programming
    Replies: 3
    Last Post: 13th December 2017, 10:30
  2. QGraphicsItem doesn't inherit QObject?
    By xyzt in forum Qt Programming
    Replies: 6
    Last Post: 26th September 2011, 14:59
  3. QGraphicsView, QGraphicsItem, QGraphicsScene
    By Shuchi Agrawal in forum Newbie
    Replies: 10
    Last Post: 23rd March 2011, 20:50
  4. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  5. Snap-to grid on QGraphicsItem
    By hardgeus in forum Qt Programming
    Replies: 9
    Last Post: 28th April 2008, 16:22

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.