Results 1 to 6 of 6

Thread: force redraw of every graphicsitem

  1. #1
    Join Date
    Feb 2006
    Posts
    209
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default force redraw of every graphicsitem

    I'm having a little problem with redrawing in a graphicsview/scene.
    If I scroll to another position of the scene, there are some graphicsitems that are not redrawn.
    See the picture. There you can see how the boxes are redrawn, but the lines with the integers on are not always drawn, 4 of them are just started, but not finished.

    The integers are QGraphicsTextItems that has a customized paint() function that draws a line beneth the integer.

    I'm not sure how to make it do a proper redraw of the scene.
    Attached Images Attached Images

  2. #2
    Join Date
    Feb 2006
    Posts
    209
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Question Re: force redraw of every graphicsitem

    I added

    void MainWindow::resizeEvent(QResizeEvent* e)
    {
    scen->update(scen->sceneRect());
    }

    to the mainwindow class, but even this doesn't handle redrawing properly.

    B.t.w, what setting should I use to make the graphicsview NOT scrolling back to some strange default setting if I scroll to the right for example and add something that changes the scene (then the view scrolls to the left corner).

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

    Default Re: force redraw of every graphicsitem

    Does boundingRect() return proper rects for all the items?

    Calling update() won't do anything if the items have invalid bounding rects.

  4. #4
    Join Date
    Feb 2006
    Posts
    209
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default Re: force redraw of every graphicsitem

    I added this:

    QRectF Svar::boundingRect() const
    {
    return QRectF(-30,-20,60,40);
    }

    Svar is derived from QGraphicsTextItem.

    It stills seems to be some problem, It is difficult to double click on the Svar items to. If I click like a frustrated user, then I might hit it with a click. Really strange, but perhaps related?

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

    Default Re: force redraw of every graphicsitem

    When implementing custom graphics items, you have to make sure boundingRect() and shape() return proper data:
    - boundingRect should return a rectangle which should be marked as dirty and redrawn when the item changes
    - shape should return a shape of the item you wish to use for collision detection (which is used for "clicking" on an item as well).

    In your situation make sure boundingRect and shape() take into consideration the lines you added.

    BTW. Maybe you should inherit from QGraphicsAbstractShapeItem instead of QGraphicsTextItem?

  6. #6
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 38 Times in 30 Posts

    Default Re: force redraw of every graphicsitem

    Make sure you call QGraphicsItem:repareGeometryChange() if you ever change the item's bounding rect (i.e., the return value of boundingRect()).

    http://doc.trolltech.com/4.2/qgraphi...GeometryChange
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

Similar Threads

  1. Force redraw of QSimpleRichText when QStyleSheet changes
    By SHesselbarth in forum Qt Programming
    Replies: 1
    Last Post: 12th April 2006, 17:10
  2. QT4 beginner Fatal Error
    By Remyfr in forum Installation and Deployment
    Replies: 3
    Last Post: 11th March 2006, 02: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.