Results 1 to 7 of 7

Thread: add points/path to QGraphicsView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: add points/path to QGraphicsView

    all right, thank you a lot, I'll come back soon with the errors...
    but honestly thanks, I think now I get it. off to try.


    Added after 6 minutes:


    Bearhug for JohannesMunk!

    For some similarly beginner's interest the whole code together:
    the derived class declaration:
    Qt Code:
    1. class myQGraphichsItem : public QGraphicsItem
    2. {
    3. private:
    4. QRect bRect;
    5. public:
    6. myQGraphichsItem();
    7. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    8. QRectF boundingRect() const{ return bRect; }
    9. void setBoundingRect(int x1,int y1,int x2,int y2){bRect = QRect(x1,y1,x2,y2);}
    10. };
    To copy to clipboard, switch view to plain text mode 
    the paint method reimplemented:
    Qt Code:
    1. void myQGraphichsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    2. {
    3. painter->drawRect(boundingRect());
    4. }
    To copy to clipboard, switch view to plain text mode 
    in useage:
    Qt Code:
    1. myQGraphichsItem *mgi = new myQGraphichsItem;
    2. mgi->setBoundingRect(30,60,90,100);
    3. scene->addItem(mgi);
    4. ui->graphicsView->setScene(scene);
    To copy to clipboard, switch view to plain text mode 
    Last edited by szisziszilvi; 13th January 2011 at 13:34.
    Szilvi

Similar Threads

  1. Replies: 1
    Last Post: 21st December 2010, 22:04
  2. Points selection
    By CCTeam in forum Qt Programming
    Replies: 1
    Last Post: 7th June 2010, 14:22
  3. Replies: 8
    Last Post: 17th October 2009, 08:10
  4. drawing an Arc using points
    By chethana in forum Qt Programming
    Replies: 2
    Last Post: 11th July 2009, 03:59
  5. Plotting points
    By afflictedd2 in forum Qt Programming
    Replies: 8
    Last Post: 26th February 2009, 08:20

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.