Results 1 to 3 of 3

Thread: GraphicsView paintEvent() method implementation problem

  1. #1
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Question GraphicsView paintEvent() method implementation problem

    Dear Friends
    If I reimplement paintEvent() method of QGraphicsView then all my previously painted graphicsItems are going off from the screen

    Actually like this

    Qt Code:
    1. class GraphiscScene : public QGraphicsScene
    2. {
    3. Q_OBJECT;
    4. }
    5. GraphiscScene::GraphicsScene()
    6. {
    7. setBackgroundBrush(Qt::black);
    8. }
    9.  
    10. class GraphicsView:public QGraphicsView
    11. {
    12. Q_OBJECT
    13. public:
    14. GraphicsView(GraphicsScene *Scene);
    15. void paintEvent(QPaintEvent *event); // if I add this part and implement it my screen is getting white. and no items are visible.
    16. }
    17.  
    18. GraphicsView::GraphicsView(GraphicsScene *Scene)
    19. {
    20. setScene(Scene);
    21. }
    22. // previously this was not there...Now I want to implement paintEvent to draw a rectangle on the screen.But if I add this part my screen is getting white.
    23. void GraphicsView::paintEvent(QPaintEvent *event)
    24. {
    25. }
    26.  
    27. class MainWindow:public QMainWindow
    28. {
    29. Q_OBJECT
    30. public:
    31. GraphicsView *view;
    32. GraphicsScene *scene;
    33. }
    34.  
    35. MainWindow::MainWindow()
    36. {
    37. scene = new GraphicsScene;
    38. view = new GraphicsView(scene);
    39. view->show();
    40. }
    41.  
    42. // After creating a view and scene like this I am creating some GraphicsItems and adding them to into the scene
    43. // They're being displayed nicely on the screen
    44. // Now I want to draw a dynamic rectangle starting from mousePree point to mouseRelease point and that iwant to draw on the screen
    45. // For that I need to reimplement paintEvent() method of the GraphicsView
    46. // But when I try to implement that my intial view which should be black screen is getting white and no items are visible in the view.
    To copy to clipboard, switch view to plain text mode 

    Can anyone tell what I am doing wrokng in thisi ???
    Last edited by e8johan; 15th August 2009 at 17:07.

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: GraphicsView paintEvent() method implementation problem

    Please, try to use code tags where possible.

  3. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: GraphicsView paintEvent() method implementation problem

    void paintEvent(QPaintEvent *event);
    in case of using paintEvent on view u can use ..

    Qt Code:
    1. QGraphicsView::drawBackground(QPainter *, const QRectF &)
    To copy to clipboard, switch view to plain text mode 

    this will help u painting on QGraphicsScene()
    "Behind every great fortune lies a crime" - Balzac

Similar Threads

  1. QSound Problem with GraphicsView
    By QbelcorT in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 14th January 2009, 12:28
  2. Some problem with painter's fillpath() method
    By salmanmanekia in forum Qt Programming
    Replies: 8
    Last Post: 30th June 2008, 13:31
  3. paintEvent problem
    By anafor2004 in forum Newbie
    Replies: 1
    Last Post: 29th June 2008, 14:18
  4. graphicsview performance problem
    By kernel_panic in forum Qt Programming
    Replies: 16
    Last Post: 23rd December 2007, 18:19
  5. GraphicsView rotate problem
    By forrestfsu in forum Qt Programming
    Replies: 7
    Last Post: 21st November 2007, 20: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.