Results 1 to 11 of 11

Thread: Efficient Scaling and Rotating of QGraphicsView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Posts
    83
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: Efficient Scaling and Rotating of QGraphicsView

    No, I don't use OpenGL to draw the background. I do use painter and here is the code:

    Qt Code:
    1. void Override::drawBackground(QPainter *painter, const QRectF &rect)
    2. {
    3. painter->save();
    4. painter->setBrush(Qt::black);
    5. painter->drawRect(rect);
    6. painter->drawPixmap(0,0, theForm->getBackground()); // getBackground() returns a pixmap
    7. painter->restore();
    8. }
    9.  
    10. QPixmap theForm::getBackground()
    11. {
    12. return backgroundImage; // This is an image stored in a classes QPixmap variable.
    13. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by forrestfsu; 8th December 2006 at 18:39.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    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: Efficient Scaling and Rotating of QGraphicsView

    I'm not sure, but it is possible that you need to draw the background using OpenGL code. Unfortunately "chips" doesn't draw a background, so we can't check in the example...

    The pixmap you're using is very big, so obviously transforming it is very expensive. I understand that the background is getting rotated and scaled when items get scaled and rotated, correct?

  3. #3
    Join Date
    Oct 2006
    Posts
    83
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: Efficient Scaling and Rotating of QGraphicsView

    I'm not quite sure I understand what you mean by "the background is getting rotated and scaled when items get scaled and rotated." So I'll try and explain:

    This specific graphicsView has a scene which it shares with 5 other graphicsView's. The only difference with this graphicsView is that I use drawBackground() to give it a unique background Pixmap (in this case a very large pixmap). I have zoom and rotate buttons on the widget which call the ScaleView() function for this graphicsView. ScaleView() scales and rotates all the contents within this graphicsView (the scene contents and the large background Pixmap).

    Hope this clears it up.

  4. #4
    Join Date
    Oct 2006
    Posts
    83
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: Efficient Scaling and Rotating of QGraphicsView

    An additional note. Once the user has scaled the image to a different ratio then the original, even using the scroll bars for the graphicsView lag moving the content of the graphicsView.

  5. #5
    Join Date
    Oct 2006
    Posts
    83
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: Efficient Scaling and Rotating of QGraphicsView

    I just fixed the problem (still a few minor bugs to go through). Instead of returning an entire Pixmap, I needed only return the area of the Pixmap that I needed to display using the QPixmap's copy function. After I have all the code in place I will paste it for review.

    Thanks Wysota for all your help on this issue.

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.