Results 1 to 6 of 6

Thread: Set EllipseItem center to position

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Set EllipseItem center to position

    Hi guys,

    I have an ellipeItem( QREctF(0,0,6,6)) set to ignore transformations.
    When the user clicks on the scene the item is shown in that place. Using "setPos(qreal,qreal)" sets the position of the item, but its' topLeft bounding rectangle point not the center. I am currently trying to set the items' center to that point.
    Sounds simple, but how to achieve this?

    THanks.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Set EllipseItem center to position

    Return a boundingRect of (-3,-3,6,6).

  3. #3
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Set EllipseItem center to position

    Hmm...

    Ok. Let's say I have zoomed 100times. The bounding rect is the same(the same width/height), but the coordinates(distance between) changed. AM I right? If yes, the idea above is wrong.

    If the item would not ignore the transformations I could use sth like this:
    Qt Code:
    1. item->boundingRect();
    2. item->setRect(boundingRect.moveCenter(_pos));
    To copy to clipboard, switch view to plain text mode 

    And it would work, but the size of the item would change thougt, and I do not want that.
    Kacper
    Last edited by maverick_pol; 15th May 2008 at 12:20.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  4. #4
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Set EllipseItem center to position

    This is a part of my code which I would like to work:
    Qt Code:
    1. m_originationPoint = m_scene->addEllipse(0,0,6,6);
    2. m_originationPoint->setFlag(QGraphicsItem::ItemIgnoresTransformations);
    3. m_originationPoint->setZValue(1);
    4. ......
    5. void MyClass::vSetPos(QPointF _pos) {
    6. m_originationPoint->setPos(_pos);// This sets the topLeft boundingRect
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for any ideas.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Set EllipseItem center to position

    Simply make the ellipse start from -3, -3 and extend 6 units wide and 6 unit high instead of 0,0 and 6,6. It should all work then - setPos() will set the position of the centre of the ellipse.

  6. The following user says thank you to wysota for this useful post:

    maverick_pol (15th May 2008)

  7. #6
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Set EllipseItem center to position

    Hi,

    Unfortunately, for me, your are totally right. This works.
    Why unfortunately? Because I have found a different solution, which was far more complex and I coded it.
    Ok...Sorry for the stupid problem.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

Similar Threads

  1. Drawing QGraphicsSvgItem from center
    By Mhondoz in forum Qt Programming
    Replies: 3
    Last Post: 14th March 2008, 20:33

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
  •  
Qt is a trademark of The Qt Company.