Results 1 to 5 of 5

Thread: Drawing on QPixmap fails / How to convert QPitcure to QPixmap

  1. #1
    Join Date
    Jan 2008
    Posts
    56
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Drawing on QPixmap fails / How to convert QPitcure to QPixmap

    Hi all,

    i need to draw a pixmap on a widget which consists about 6 or 7 images.
    When I draw directly on the widget in paintEvent, everything is fine.
    Now, I want to draw the pixmap once and save it, then, just put it on the widget in paintEvent. However, this does not work correctly.
    A snippet of code follows:
    Qt Code:
    1. QPainter painter(&pixmap);
    2. painter.drawPixmap(3, 3, pixmapBG);
    3. // and some more commands
    4. painter.end(); // painting done
    To copy to clipboard, switch view to plain text mode 
    pixmap is a member of my class.

    This gives me a message:
    QPainter::begin: Paint device returned engine == 0, type: 2

    When I use a QPicture instead, it works. QImage also doesn't work.
    I don't understand why.
    I could use a QPicture for painting and replay it everytime, however, the performance is poor.
    Is it possible to convert QPicture to QPixmap? I didn't find anything about that.
    I could use play, but then I need to use QPainter painter(&pixmap) again which doesn't work for me.

    I use Qt 4.4.0 on WindowsXP and Vista.

    Thanks for any hint.

    Regards,

    Rainer

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drawing on QPixmap fails / How to convert QPitcure to QPixmap

    Did u use QPainter::begin ??

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drawing on QPixmap fails / How to convert QPitcure to QPixmap

    How do you create that pixmap? Does it have a size?

  4. The following user says thank you to jacek for this useful post:

    RThaden (28th August 2008)

  5. #4
    Join Date
    Jan 2008
    Posts
    56
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drawing on QPixmap fails / How to convert QPitcure to QPixmap

    Thanks for your replies.

    1. When you pass the pixmap or picture in the constructor of QPainter, you don't have to use begin, AFAIK.

    2. No, it doesn't have a size. It's just

    Qt Code:
    1. QPixmap pixmap;
    To copy to clipboard, switch view to plain text mode 

    Is that relevant?

    Best regards,

    Rainer

  6. #5
    Join Date
    Jan 2008
    Posts
    56
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: Drawing on QPixmap fails / How to convert QPitcure to QPixmap

    Thanks Jacek, it was the size.
    I just tested
    Qt Code:
    1. QPixmap pixmap(600,400);
    2. QPainter(&pixmap);
    To copy to clipboard, switch view to plain text mode 
    and that works.

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.