Results 1 to 10 of 10

Thread: QGraphicsItems somtimes not diplaying

  1. #1
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsItems somtimes not diplaying

    Hello all, I have a rather weird problem.

    I have a class started in QThread which sends via signals/slots to another class information for a QGraphicsItems which are then placed on the QGraphicsScene. The problem arises when I send too many of these items....sometimes some items simply don't get diplayed; it is completely random which ones don't get drawn on the scene...and it is always just a couple that don't get displayed...the majority 98% or so always do...

    here is my code in the slot that catches the signal from the thread.

    void myClass::getItem(...){
    m_items.push_back(new itemOnScene(...));
    m_mainScene->addItem(items.back());
    m_items.back()->setPos(QPointF(0, 0));
    m_items.back()->setVisible(true);//defualt is true anyways...just to make sure...
    m_items.back()->update();//just to make sure...
    }

    if I add Sleep(10); after the update call all items are displayed 100% of the time...what's going on with QT? A signal being sent too close after a previous one gets lost? What's going on here? Does this have to do with how items are painted?

    Thanks for your help in advance...a truly baffling problem...

    Jonathan

    Edit://even works all the time with Sleep(1);
    Last edited by JonathanForQT4; 1st June 2007 at 14:18.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsItems somtimes not diplaying

    Could you verify that the slot is called each time an item should be added? It'd help to see if the problem is within the slot or outside it.

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItems somtimes not diplaying

    If you add a lot of items in a short period of time, then don't call update for each and every one of them. Call update once, after you finished adding all the items.

    This most likely is some update problem, rather than a signal/slot problem.

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItems somtimes not diplaying

    By the way u are adding the items at (0,0) . That might be a problem in updating as marcel told. Try positioning them at different positions and see if the problem exists.

  5. #5
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsItems somtimes not diplaying

    I should add that I move it to 0, 0 at first because I get another signal sent to a slot which then sets the bounding rect to where the rectangle should be painted.

    When I create the qgraphicsitem I do not know where it should be placed..this comes afterwards due to the class (which is the qthread) communicating with another program.

    So the sequence of events is:

    code posted above.

    m_items.back()->setRect(rect_passed_in_through_signal);

    Within the QGraphicsItem (note:rect_passed_in_through_signal == m_rect) :

    QRectF item::boundingRect() const{

    return QRectF(m_rect);
    }

    void item:aint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){

    ...

    painter->drawRect(m_rect);
    ...
    }

    marcel: calling update afterwards does not help.
    wysota: each slot is called for sure, when I trace through the program while debugging the problem does not happen.
    aamer4yu: why would this help anything?

  6. #6
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsItems somtimes not diplaying

    could it be that the boundingRect() or Paint() within the qgraphicsitem is called before the signal with setRect is called...?

    I'm guessing it has to do with m_rect in the Qgraphicsitem not getting set at the right time somehow...because sometimes you can see the item on the scene, but when you zoom in it's not actually there...which would seem like it's getting painted there but the bounding rect is false or something....any ideas?

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItems somtimes not diplaying

    I hope that will help because u are using threads...
    see u are adding too many items at once... and it will depend how the paint of the items will be called. U said the problem is not there when u add sleep... so i guessed that might be the problem
    Also try not to draw until u are not passed the rectangle... u can keep some extra variable for that check.

  8. #8
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsItems somtimes not diplaying

    tried changing the setPos...in the same slot that catches the signal with the rect....and it's not working.

    I've tried setting the pos to lowerleft, upperleft.....I don't see the rect anywhere now.....but am still trying things

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsItems somtimes not diplaying

    Could you explain what the thread does? Maybe some relevant code would clear up things a little bit...

  10. #10
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsItems somtimes not diplaying

    what's going on in the thread is that the program is getting the rectangles to be displayed on the scene and sends them via signal/slot...if you need to know more read my other threads, I think I explain it more in detail there.

    The thing to note is that I can get a notice that there is an object of type x and thereafter then get a notice of type y object....but the rect for object x comes sometime after y, therefore the different methods.

    In any case, I have been doing some futzing around and found out that when the boundrect function is called and the m_rect has not been set....the object is then not seen...

    so just before I set the m_rect I now call prepareGeometryChange() and everything works fine

    edit://damnit, why can't I add thanks to myself :P

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.