Results 1 to 4 of 4

Thread: QGraphicsItem are not painted any more

  1. #1
    Join Date
    Jan 2017
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QGraphicsItem are not painted any more

    Ht all,

    I am a bit new so some basic stuff i might not know. SOrry if this post should have been on the newbie section but I am not sure it s that simple.

    So, I've started from example DiagramItem and added the following:
    - a poolThread (producer consumer type) to update a value from each DiagramItem every 1s. More exactly, the background according to the result of a QProcess return code. After the value is changed, the item->update() is called
    - a Graphics_view_zoom
    - a symbol to draw in the DiagramItem when mouse hover

    I am using QMutexLocker for thread safe, and no I am not using signals to communicate between the threads and the Items, just changing a value and call update().

    Everything works fine at start, but after a while (couldn't find what happens), the items paint function is not called, even when i have the mouse one it. ONLY when zooming in/out does it update for a moment.
    I can post section from code if needed.

    I need help with this please!
    Many thanks

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,246
    Thanks
    304
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QGraphicsItem are not painted any more

    You generally can't call methods on UI objects from any thread except the main thread (the one that starts when your application does). All of the UI objects live in this main thread. You can't create or modify UI objects from any other thread.

    The only good way to update something in a UI object from a different thread is to make a signal / slot connection between the UI object and the worker thread. The signal will be handled properly across threads and the slot will be executed in the UI thread by the Qt event loop running in that thread, so no need for mutexes or other synchronization.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    dfroze (21st January 2017)

  4. #3
    Join Date
    Jan 2017
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem are not painted any more

    Thank you @d_stranz for your fast response.

    I've modified it, seems that after I added the signal/slot style and fixed a memory leak (yeah, this somehow affected the behavior as well), it started to work ok, for now ... I'll be back with a final conclusion soon.

  5. #4
    Join Date
    Jan 2017
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem are not painted any more

    So far so good. Thank you.

Similar Threads

  1. QPainter above already painted
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 26th February 2014, 20:59
  2. Removing last Painted point
    By ebsaith in forum Qt Programming
    Replies: 10
    Last Post: 2nd July 2013, 11:37
  3. dialog content is not painted
    By miso in forum Qt Programming
    Replies: 7
    Last Post: 12th March 2013, 15:12
  4. QDialogButtonBox text not painted
    By kshi in forum Qt Programming
    Replies: 0
    Last Post: 8th January 2011, 01:41
  5. How to erase everything widget has painted?
    By TheNewGuy in forum Newbie
    Replies: 1
    Last Post: 12th December 2009, 08:23

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.