Results 1 to 5 of 5

Thread: Multiple use of QGraphicScene

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Multiple use of QGraphicScene

    Hi all,

    I'm quite new here and just started with Qt for a couple of days. Currently I'm working on my first project with Qt and I'm trying to draw some kind of map where a few red dots will become visible after putting data in a table.

    I've already created a ui in Qt with a QGraphicsView included. Then created a QGraphicsScene named 'scene'. In that scene i draw a few circles and lines with the following code:

    Qt Code:
    1. //draw map
    2. void Unknown::drawMap(int width)
    3. {
    4. scene->setSceneRect(0, 0, width, width);
    5. scene->setBackgroundBrush(Qt::white);
    6.  
    7. //draw horizontal & vertical line
    8. scene->addLine(0, (width/2), width, (width/2));
    9. scene->addLine((width/2), 0, (width/2), width);
    10.  
    11. //draw 5 circles
    12. int x = (width/12), y = width-(width/6);
    13. for(int i=0; i<5; i++)
    14. {
    15. scene->addEllipse(x, x, y, y, QColor(180, 180, 180), Qt::NoBrush);
    16. x = x + (width/12);
    17. y = y - (width/6);
    18. }
    19.  
    20. //put scene on screen
    21.  
    22. ui->graphicsView->setScene(scene);
    To copy to clipboard, switch view to plain text mode 
    This works like a charm. However, when this function is finished I would like to add some red dots to this QGraphicsScene with a different function.
    Qt Code:
    1. //draw dot
    2. void Unknown::drawDot()
    3. {
    4. scene->addEllipse(50, 50, 1, 1, QColor(255, 0, 0), Qt::NoBrush);
    5. ui->graphicsView->setScene(scene);
    6. }
    To copy to clipboard, switch view to plain text mode 
    When applying this function to the main program and build it, I get the error: "scene not declared". I do understand why, but I don't know how to solve this problem without getting errors. I already tried the following in the main program:
    Qt Code:
    1. #include "unknown.h"
    2. #include "ui_unknown.h"
    3.  
    To copy to clipboard, switch view to plain text mode 
    When adding this to the program, the building process completes succesfully. The program shuts down immediately though.

    Can someone help me out here?
    Last edited by Xtresis; 6th September 2010 at 10:59.

Similar Threads

  1. how to use Multiple timers?
    By qtlinuxnewbie in forum Newbie
    Replies: 8
    Last Post: 21st September 2012, 09:01
  2. Multiple QWidgets
    By codeman in forum Qt Programming
    Replies: 7
    Last Post: 23rd March 2010, 11:21
  3. multiple sort
    By baray98 in forum Qt Programming
    Replies: 3
    Last Post: 25th August 2009, 08:43
  4. multiple defination
    By phillip_Qt in forum Qt Programming
    Replies: 4
    Last Post: 13th December 2007, 17:32
  5. Replies: 0
    Last Post: 21st December 2006, 11:48

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.