Results 1 to 3 of 3

Thread: Rotating QGraphicsEllipseItem, but keeping its location

  1. #1
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Rotating QGraphicsEllipseItem, but keeping its location

    I have a QGraphicsEllipseItem which I would like to rotate, but place on a certain location of the scene. I can get it to rotate, but it seems to automatically place the ellipse somewhere else on the scene. This is a snippit of the code I have so far, any help would be appreciated.

    Qt Code:
    1. ellipse = new QGraphicsEllipseItem(x-1, y-7, 2, 7);
    2. ellipse->rotate(45.0);
    3. // Tried the following with no success:
    4. // ellipse->setPos(x,y);
    5. // ellipse->setPos(ui.graphicsView->mapFromScene(x,y));
    6. // ellipse->setPos(ui.graphicsView->mapToScene(x,y));
    7. scene->addItem(ellipse);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotating QGraphicsEllipseItem, but keeping its location

    Could you post a screenshot, so we can see what's wrong?

  3. #3
    Join Date
    Feb 2012
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Rotating QGraphicsEllipseItem, but keeping its location

    This is how i made it.


    foreach(QGraphicsItem *item, graphicScene->selectedItems()){
    QString val = item->data(1).toString(); // This check is merely because I have 1 parent QGraphicsItem which is not intended to rotate
    if(val.isEmpty()){
    QRectF br= item->boundingRect();
    item->setTransformOriginPoint(br.center());
    item->setRotation(item ->rotation() + 10.0);
    item->update();
    graphicScene->update();

    }
    }
    Last edited by Hannu Männistö; 9th February 2012 at 12:54.

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.