Results 1 to 7 of 7

Thread: item local coordinate

  1. #1
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question item local coordinate

    I'd like to have each rect item on the scene, with the local (0,0) coordinate in the centre of the rect.

    If i'd like to obtain a rect item with this attribute, a write:
    Qt Code:
    1. QRectF area(-25,-25,50,50)
    2. myrect = new rectitem(bla,bla,area);
    3. setPos("pos in the scene where i'd like to put my item")
    To copy to clipboard, switch view to plain text mode 

    I build the rect in this mode: QRectF area(-width/2,-height/2,width,height);

    The problems come, when i resize the rect.
    When i resize it, i use the setRect() function, where i set the new rect.
    At the end of resize, the local coordinate (0,0) doesn't match with the centre of my item. How can i obtain this behaviour??

  2. #2
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: item local coordinate

    here my specific code for the vertical resize:
    Qt Code:
    1. void bottom_resize(){
    2. QRectF r=rect();
    3. r.setBottom(event->pos().y());
    4. setRect(r);
    5. scene()->update();
    6. }
    To copy to clipboard, switch view to plain text mode 

    How can I mantein the local coordinate (0,0) on the centre of my resized item???

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

    Default Re: item local coordinate

    Change the boundingRect() implementation. It is the one deciding about coordinates.

  4. #4
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: item local coordinate

    can i have an example?????

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

    Default Re: item local coordinate

    Sorry, an example of what? Returning of a QRect object?

  6. #6
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: item local coordinate

    if the code is :

    Qt Code:
    1. QRectF myItem::boundingRect() const{
    2. return rect();
    3. }
    To copy to clipboard, switch view to plain text mode 

    ....so i don't resolve the problem.

    The item coordinate (0,0) doesn't match with the centre of the item.

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

    Default Re: item local coordinate

    The rect you return has to correspond to the coordinates. If you increase the size of the rectangle and want the (0,0) point to remain in the middle of the rectangle, the upper left corner has to change its coordinates. Otherwise you're just extending the rectangle one way.

Similar Threads

  1. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  2. Replies: 1
    Last Post: 19th April 2007, 22:23
  3. how change the QListBox item position by pixel
    By roy_skyx in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 01:34

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.