Results 1 to 3 of 3

Thread: Image/Pixmap after scaling parcelled into 4 pieces.

  1. #1
    Join Date
    Feb 2011
    Posts
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Symbian S60 Maemo/MeeGo

    Default Image/Pixmap after scaling parcelled into 4 pieces.

    Hi all, I have a board desk and using some image as background, it's saved in svg file and I render it from there to a pixmap/image. Then I scale it to size of QGraphicsView on renderEvent. But a problem is that pixmap/image is parcelled after the scaling.

    There is a screenshot of the problem as attachment.

    I would love to have the background in one piece not parcelled, what am I doing wrong?

    Here's the renderEvent implementation:
    Qt Code:
    1. void kMancalaBoard::resizeEvent ( QResizeEvent *event ) {
    2. qDebug("Resize event ... ");
    3. QSize sz(400, 300);
    4.  
    5. qDebug("Width: %d, Height: %d", sz.width(), sz.height());
    6.  
    7. QPixmap bg ( QSize(400, 200) );
    8. QPainter bgPainter ( &bg );
    9.  
    10. if ( m_renderer->elementExists ( QString ( "background" ) ) ) {
    11. qDebug ( "Rendering" );
    12. m_renderer->render ( &bgPainter, QString ( "background" ), QRectF ( QPointF ( 0,0 ), sz ) );
    13. } else {
    14. qDebug ( "No background found" );
    15. }
    16.  
    17. QSize hint = size();
    18. qDebug("Width: %d, Height: %d", hint.width(), hint.height());
    19.  
    20. QBrush br ( bg.scaled(hint, Qt::IgnoreAspectRatio, Qt::SmoothTransformation) );
    21. m_scene->setBackgroundBrush ( br );
    22.  
    23. QGraphicsView::resizeEvent ( event );
    24.  
    25. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Image/Pixmap after scaling parcelled into 4 pieces.

    Wow, what's about reimp the paint method of your view and print the images directly? the painters drawPixmap method will scale the image on its own.

  3. #3
    Join Date
    Feb 2011
    Posts
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Symbian S60 Maemo/MeeGo

    Default Re: Image/Pixmap after scaling parcelled into 4 pieces.

    I'm not sure how to do that and if it would help. Problem is in setting setBackgroundBrush, if I put a image to scene as scene->addPixmap(...) image is ok. So problem is somewhere in scene painting with brush.


    Added after 23 minutes:


    Finally I solved that by reimplementing drawBackground of the view as you suggested.

    Qt Code:
    1. void kMancalaBoard::drawBackground(QPainter *painter, const QRectF &rect) {
    2. if ( m_renderer->elementExists ( QString ( "background" ) ) ) {
    3. qDebug ( "Rendering" );
    4. m_renderer->render ( painter, QString ( "background" ), rect);
    5. } else {
    6. qDebug ( "No background found" );
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Douglish; 19th February 2011 at 10:28.

Similar Threads

  1. QLabel->pixmap not scaling properly and breaking the layout
    By Jon Heron in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 21st November 2010, 16:54
  2. Pixmap scaling problem
    By tommy in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2009, 18:00
  3. Replies: 8
    Last Post: 12th March 2009, 15:12
  4. finding maximum scaling of a pixmap
    By babu198649 in forum Newbie
    Replies: 1
    Last Post: 31st March 2008, 15:32
  5. Pixmap scaling
    By yellowmat in forum Newbie
    Replies: 3
    Last Post: 4th January 2007, 17:01

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.