Results 1 to 4 of 4

Thread: Centralizing various GraphicsItem in QGraphicsView

  1. #1
    Join Date
    Sep 2008
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Centralizing various GraphicsItem in QGraphicsView

    Hi,

    I am trying to draw a QPolygon of QVectors in a QGraphicsScene.

    Depends on some conditions, n numbher of polygon is added in the graphicsview and it has been drawn in different places of the view... like first polygon is placed in left bottom of the QGV, second is at right bottom, etc in a random manner...

    I would like to place all the polygons in a central axis like in the After_Centralization.jpg image... (Rfer Before_Centralization)...

    Please help me on acheiving this?

    Regards
    Ranna
    Attached Images Attached Images

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

    Default Re: Centralizing various GraphicsItem in QGraphicsView

    But what exactly is the problem? Just set the position of the items using QGraphicsItem::setPos().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2008
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Centralizing various GraphicsItem in QGraphicsView

    The problem scenario is below:

    1. A list of polygons are displayed in the left side of the widget.
    2. On the right side of the widget a preview area is there with QGraphicsView widget..
    3. The user can select a polygon from the left side and the selected polygon is displayed in
    the right side preview area...
    4. The selected polygons are scattered at different points of QGraphicsView.
    5. I require that the polygons should be drawn in correct order as you can see in the attachement AFter_Centralization.jpg.

    I am adding the polygon like below

    Qt Code:
    1. DrawPolygon(int xOffset, int yOffset)
    2. {
    3. QGraphicsView *ptrGraphicsView = new QGraphicsView();
    4. QGraphicsScene *polyScene = new QGraphicsScene();
    5. QVector <QPointF> vctPoints;
    6. for(int i=xOffset; i<10; i++)
    7. {
    8. for(j=yOffset; j<10; j++)
    9. {
    10. vctPoints.append(QPointF(i*50,j*50));
    11. }
    12. }
    13. QPolygon *polygon = new QPolygon(vctPoints);
    14. polyScene->addPolygon(polygon);
    15. ptrGraphisView->setScene(polyScene);
    16. }
    To copy to clipboard, switch view to plain text mode 

    The above function draws polygon considering different offset values... and so the polygons get scattered in the QGV...

    I want to place the scattered polygons in a central axis...

    Regards
    Ranna
    Last edited by wysota; 16th June 2009 at 10:48. Reason: missing [code] tags

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

    Default Re: Centralizing various GraphicsItem in QGraphicsView

    You can use QGraphicsItem::moveBy() to move the items in the horizontal axis. Just take the boundingRect() of the item, and calculate the offset between its centre and the centre of your scene and pass that value to moveBy().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 21
    Last Post: 3rd April 2009, 12:22
  2. Replies: 0
    Last Post: 5th March 2009, 06:54
  3. Replies: 2
    Last Post: 26th February 2009, 10:12
  4. QGraphicsView and embeded widgets
    By bunjee in forum Qt Programming
    Replies: 10
    Last Post: 12th October 2008, 07:43
  5. Problem determining size of QGraphicsView
    By Bocki in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2008, 14: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.