Results 1 to 11 of 11

Thread: QGraphicsView, QGraphicsItem, QGraphicsScene

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    37
    Thanked 53 Times in 40 Posts

    Default Re: QGraphicsView, QGraphicsItem, QGraphicsScene

    Quote Originally Posted by Shuchi Agrawal View Post
    hi,
    can anyone make me clear with the difference b/w QGraphicsView, QGraphicsItem and QGraphicsScene . i studied fm the documentation but still i m not clear how to use them.
    i want to draw a line on a menu click or when i click at a point n drag n release. so where to write code for this? in QGraphicsView, QGraphicsItem or QGraphicsScene ?
    thanks in advance
    GraphicsView framework is pretty well organised and documentation is also good. You only need to read, do the examples and tutorials.
    Anyway to put it in simple words QGraphicsScene is the offscreen container for QGraphicsItem's. QGraphicsItem are objects that represent the shapes or anything to be drawn and managed. QGraphicsView is the viewer widget which enables to "view" the scene.

    For your second question
    Just create QGraphicsView and QGraphicsScene in your mainwindow constructor like this

    Qt Code:
    1. MainWindow::MainWindow()
    2. {
    3. QGraphicsView *view = new QGraphicsView(this);
    4. // Here scene is supposed to be member variable since u need it later
    5. // also you can give any geometry of scene
    6. scene = new QGraphicsScene(0,0,1024,800);
    7. view->setScene(scene);
    8. ...
    9. }
    To copy to clipboard, switch view to plain text mode 

    Now just create QGraphicsLineItem's when you need to draw line. For eg assuming the below slot to be called from menu do the following
    Qt Code:
    1. MainWindow::slotOnMenuClick()
    2. {
    3. QGraphicsLineItem *line = new QGraphicsLineItem( required line);
    4. scene->addItem(line);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Drawing lines on clicking and dragging needs you to reimplement QGraphicsScene and in that reimplement mouse*Events() which will require some knowledge about the framework. Go through the examples and documentation.
    Last edited by Gopala Krishna; 30th January 2007 at 12:06. Reason: spelling error
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  2. The following user says thank you to Gopala Krishna for this useful post:

    Shuchi Agrawal (31st January 2007)

Similar Threads

  1. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  2. Using QGraphicsView with model/view programming
    By JLP in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 11:04
  3. QGraphicsScene and QThread
    By tts80 in forum Qt Programming
    Replies: 5
    Last Post: 10th January 2007, 09:32
  4. QGraphicsView and QGraphicsScene speeds
    By jnk5y in forum Qt Programming
    Replies: 2
    Last Post: 20th October 2006, 07:13
  5. (QT4.2-RC1) QGraphicsScene QGraphicsView QGraphicsItem
    By antonio.r.tome in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 10:56

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.