Results 1 to 7 of 7

Thread: Custum QGraphicsItem not call the paint method

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custum QGraphicsItem not call the paint method

    Quote Originally Posted by Nosba View Post
    I tried to move my code on a private slot that is called when a button is pressed:
    How would that help?

    Quote Originally Posted by Nosba View Post
    So the paint method is not called..
    The item is still destroyed right away.

    Cheers,
    _

  2. #2
    Join Date
    Feb 2016
    Posts
    4
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11

    Default Re: Custum QGraphicsItem not call the paint method

    I finally realized.

    Qt Code:
    1. qDebug() << ui->graphicsView->size();
    2.  
    3. this->map = new Mercator_graphics_item(ui->graphicsView->size());
    4.  
    5. qDebug() << map;
    6.  
    7. ui->graphicsView->update();
    8.  
    9. draw_scene->addItem(map);
    10. draw_scene->update();
    11. ui->graphicsView->setScene(draw_scene);
    To copy to clipboard, switch view to plain text mode 

    the pointer map is declared in the header file...

    Using the new operand I allocate the map object in the Heap so it is not destroyed at the and of the slot's stack.

    Am I right or it works only by chance?

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custum QGraphicsItem not call the paint method

    Quote Originally Posted by Nosba View Post
    Am I right or it works only by chance?
    Yes, you are right.

    The problem was the really short life time of the item due to stack allocation.

    Cheers,
    _

Similar Threads

  1. Replies: 5
    Last Post: 16th September 2014, 22:37
  2. QGraphicsItem update() does not call paint() after some time??
    By kapoorsudhish in forum Qt Programming
    Replies: 1
    Last Post: 25th November 2013, 16:51
  3. QGraphicsItem: pure virtual method call problem
    By phuongot in forum Qt Programming
    Replies: 5
    Last Post: 17th January 2012, 07:35
  4. Use OpenGL in QGraphicsItem paint method
    By subsonic in forum Qt Programming
    Replies: 0
    Last Post: 27th November 2011, 14:54
  5. paint method
    By zgulser in forum Newbie
    Replies: 6
    Last Post: 20th July 2009, 08:57

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.