Results 1 to 6 of 6

Thread: [GraphicsView] drawBackground junks around

  1. #1
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default [GraphicsView] drawBackground junks around

    Hey there,

    I have a rather simple question. I have a QGraphicsView where I want to paint custom things on the background (which don't change size when the view is scaled).
    For testing purposes I started testing with painting "Test" in drawBackground:

    Qt Code:
    1. void View::drawBackground(QPainter *painter, const QRectF &rect)
    2. {
    3. painter->save();
    4. painter->setWorldMatrixEnabled(false);
    5. painter->drawText(this->rect().center(), "Test");
    6. painter->restore();
    7. }
    To copy to clipboard, switch view to plain text mode 
    To see that the scaling actually works, I've added a QGraphicsTextItem.
    Now what happens, is that when I move the graphicsView and my previously painted "Test" goes outside the viewport and then goes back in, it's gone (or partially gone, if I only partially moved it outside the viewport).

    QGraphicsView::setCacheMode(CacheNone) is set and I also tried playing around with optimization flags but nothing seemed to work.

    Can you guys give me a hint on what's going wrong? I need to use custom painting, because there's going to be a world map painted and stuff...

    Here are some screenshots for better understanding what my problem is:

  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: [GraphicsView] drawBackground junks around

    Why do you disable the matrix? It doesn't make much sense to do that...

  3. #3
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [GraphicsView] drawBackground junks around

    I have a QGraphicsView where I want to paint custom things on the background (which don't change size when the view is scaled).
    I do that so the background doesn't get scaled when the view is scaled. It should be sort of 'static'.

  4. #4
    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: [GraphicsView] drawBackground junks around

    If it is to be static to the view, then don't paint it in drawBackground which is meant to be static to the scene. Instead reimplement the paint event of the view and draw there (just remember to draw on the viewport and not the view itself).

  5. #5
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [GraphicsView] drawBackground junks around

    Well no, not static to the view. With "static" I just meant, that it shouldn't be scaled/transformed or whatsoever...

    I just want to paint 256x256 png tiles of maps. But painting the whole world/europe in the complete scene background would result in a huge pixmap and that is not efficient. So I wanted to just paint the exposed area (the one that is actually visible).

    Reimplementing QGraphicsView:aintEvent() somehow doesn't paint at all, lol...

  6. #6
    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: [GraphicsView] drawBackground junks around

    Quote Originally Posted by durbrak View Post
    Well no, not static to the view. With "static" I just meant, that it shouldn't be scaled/transformed or whatsoever...
    That doesn't explain why you disabled the world matrix... And I think your assumption is wrong - if you zoom in, the map should zoom in as well, shouldn't it?

    I just want to paint 256x256 png tiles of maps. But painting the whole world/europe in the complete scene background would result in a huge pixmap and that is not efficient.
    Take a look at the parameters passed to drawBackground.

    Reimplementing QGraphicsView::paintEvent() somehow doesn't paint at all, lol...
    Depends how you reimplement it.

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.