Results 1 to 7 of 7

Thread: Problem using drawPixmap() to do scrolling effect in QPixmap

  1. #1
    Join Date
    Jul 2009
    Posts
    8
    Thanks
    2

    Question Problem using drawPixmap() to do scrolling effect in QPixmap

    I'm trying to create a scrolling effect for painting done in a QPixmap, using a function that takes a pixmap and paints it into itself with the required deltas:
    Qt Code:
    1. void scrollGraphics(int dx, int dy, QPixmap *thePixmap)
    2. {
    3. p.begin(thePixmap);
    4. p.drawPixmap(dx, dy, *thePixmap);
    5. p.end();
    6. }
    To copy to clipboard, switch view to plain text mode 

    If dx and/or dy < 0, the graphics of thePixmap appear shifted by the correct amount. However, if I pass a value greater than 0 for dx and/or dy, drawPixmap() paints into thePixmap multiple shifted copies of itself.

    Is this a Qt bug? Or am I missing something?

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

    Default Re: Problem using drawPixmap() to do scrolling effect in QPixmap

    You're missing a fact that you are trying to overdraw something with something that is currently being overdrawn... Paint a picture, let it dry and try painting this picture again shifted 1/3 to the right only by looking at the picture. You'll soon reach a stage when what you should paint now has just been overpainted with what is 1/3 of the image to the left. I assume that's exactly what you're observing. And I'm assuming you're doing that on Windows as on Unix you'd probably just get garbage.

    Anyway... remove the pointers, work on copies - QPixmap is shared anyway.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    ajoffe (8th July 2009)

  4. #3
    Join Date
    Jul 2009
    Posts
    8
    Thanks
    2

    Default Re: Problem using drawPixmap() to do scrolling effect in QPixmap

    Dziękuję serdecznie. I now understand why I can't paint a pixmap directly into itself.

    However, I'm not completely clear on what you mean here:

    Quote Originally Posted by wysota View Post
    remove the pointers, work on copies - QPixmap is shared anyway.
    I understand that I need to make a copy of the pixmap, then paint the copy back into the original. But why are pointers bad in this case, and what do you mean by shared?

    Thanks.
    Qt 4.5 2009.01 | Qwt 5.2.0 | MinGW 5.1.4 | Windows XP SP3

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

    Default Re: Problem using drawPixmap() to do scrolling effect in QPixmap

    Quote Originally Posted by ajoffe View Post
    Dziękuję serdecznie.
    Proszę uprzejmie.

    I understand that I need to make a copy of the pixmap, then paint the copy back into the original. But why are pointers bad in this case, and what do you mean by shared
    Try something like this:

    Qt Code:
    1. QPixmap scrollGraphics(int dx, int dy, const QPixmap &thePixmap)
    2. {
    3. QPixmap result(thePixmap.size());
    4. result.fill(Qt::transparent); // optionally
    5. QPainter p(&result);
    6. p.drawPixmap(dx, dy, thePixmap);
    7. p.end();
    8. return result;
    9. }
    To copy to clipboard, switch view to plain text mode 

    And read about "implicit sharing".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem using drawPixmap() to do scrolling effect in QPixmap

    Quote Originally Posted by wysota View Post
    Proszę uprzejmie.
    hmmmm...

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

    Default Re: Problem using drawPixmap() to do scrolling effect in QPixmap

    Quote Originally Posted by MrDeath View Post
    hmmmm...
    It means "you're welcome" in Polish. It's not a multi-post foreign language conversation
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem using drawPixmap() to do scrolling effect in QPixmap

    Quote Originally Posted by wysota View Post
    It means "you're welcome" in Polish. It's not a multi-post foreign language conversation
    did i complaint? . Anyways i learned one sentence in polish though

Similar Threads

  1. QTreeView problem scrolling to end.
    By seneca in forum Qt Programming
    Replies: 7
    Last Post: 22nd December 2015, 12:08
  2. QPixmap resize problem
    By khcbabu in forum Qt Programming
    Replies: 2
    Last Post: 17th November 2008, 13:29
  3. QPixmap in QPushButton size problem
    By MarkoSan in forum Qt Programming
    Replies: 3
    Last Post: 22nd January 2008, 12:50
  4. QGraphicsView scrolling problem with 4.3.0
    By hb in forum Qt Programming
    Replies: 8
    Last Post: 30th August 2007, 22:18
  5. Replies: 2
    Last Post: 8th October 2006, 20:14

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.