Results 1 to 2 of 2

Thread: QT5 / items / setPos / graphicsView

  1. #1
    Join Date
    Feb 2017
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QT5 / items / setPos / graphicsView

    This is my code

    I'd like to setPos() but with the ui->graphicsView->setAlignment(Qt::AlignTop|Qt::AlignLeft); all the items are at left I can only change setPos(x,y); y value

    How can I do to use setPos() ?
    Qt Code:
    1. QString txt=ui->lineEdit->text();
    2.  
    3.  
    4. text->setHtml("100");
    5.  
    6.  
    7. text2->setHtml("100");
    8.  
    9.  
    10. line->setLine(0, 0, 50, 0);
    11.  
    12.  
    13. text3->setHtml("200");
    14.  
    15. sc->addItem(text);
    16. sc->addItem(text2);
    17. sc->addItem(text3);
    18.  
    19. sc->addItem(line);
    20.  
    21. text->setPos(30, 0);
    22. text2->setPos(30, 20);
    23. text3->setPos(30, 45);
    24. line->setPos(30, 40);
    25.  
    26. ui->graphicsView->setScene(sc);
    27.  
    28. ui->graphicsView->setAlignment(Qt::AlignTop|Qt::AlignLeft);
    29.  
    30. ui->graphicsView->update();
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 3rd March 2017 at 08:54. Reason: missing [code] tags

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QT5 / items / setPos / graphicsView

    In your code setPos() works, but QGraphicsView and QGraphicsScene just work like that. The thing is QGraphicsView by default fits the items in the scene, not the origin (0,0)

    To see the difference (magic) just add a rectangle and see the change.

    Qt Code:
    1. item->setRect(QRect(0, 0, 500, 500));
    2. sc->addItem(item);
    To copy to clipboard, switch view to plain text mode 

    Now your line and text items will shift
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Replies: 3
    Last Post: 11th December 2011, 11:09
  2. Qt 4.6 GraphicsView items remove problem
    By Piskvorkar in forum Qt Programming
    Replies: 10
    Last Post: 10th March 2010, 10:08
  3. QGraphicsItem setpos()
    By qtuser20 in forum Qt Programming
    Replies: 6
    Last Post: 3rd August 2009, 18:17
  4. Light items for the graphicsView
    By maverick_pol in forum Qt Programming
    Replies: 12
    Last Post: 1st November 2007, 19:51
  5. Zoom GraphicsView but not Items
    By abbapatris in forum Qt Programming
    Replies: 2
    Last Post: 15th October 2007, 20:47

Tags for this Thread

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.