Results 1 to 12 of 12

Thread: copy QPainter content to a QImage

  1. #1
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default copy QPainter content to a QImage

    Hi everybody, i want to know how can i copy all content of a QPainter object to a QImage?
    i dont have orginal widget reference. before programmers only send QPainter object to another functions.
    thanks.

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

    Default Re: copy QPainter content to a QImage

    QPainter doesn't have any "content". If you want to copy content of one paint device to another paint device, the source paint device has to allow it by providing a way to render itself using QPainter (e.g. QWidget::render()).
    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:

    danics (14th January 2013)

  4. #3
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: copy QPainter content to a QImage

    in qt3 we have bilBlt function for copy one PaintDevice to another, so if i dont know main type of paintdevice how can i copy its content in qt4, however, you mean if i know the main type i can cast it like this?

    destpainter.drawImage(0,0, (QImage) (*((QImage*)sourcepainter->device()));

    and if i havent paint device type i must using qt3support or another option?
    Last edited by danics; 14th January 2013 at 10:00.

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

    Default Re: copy QPainter content to a QImage

    Maybe you should just explain what you are trying to do?
    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
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: copy QPainter content to a QImage

    i have a old program with 170000 lines of code, i must change something in that and port it to qt 4.8, so they have so many function and only send the qpainter object to these functions , i must get a copy of all content of this painters to some images. i haven't the main widget or image reference, now how can i do this?

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

    Default Re: copy QPainter content to a QImage

    It still doesn't explain what you are trying to do. Architecture of Qt3 and Qt4 drawing differs greatly, there is no single magic call you can use.
    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
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: copy QPainter content to a QImage

    Ok, I know content of painter's, they have some symbols and i need to extract them, i know the coordinates of symbols and i know the background color too i must extract this symbol without background and load them in another widgets,
    it seems i must use bitBlt there is no other choice, am i right?

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

    Default Re: copy QPainter content to a QImage

    So is the source device a QWidget or QImage or what? Do you understand the question I am asking?
    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.


  10. #9
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: copy QPainter content to a QImage

    you want me to casting paintingdevice?
    i m sure its not qwidget its qimage or qpixmap or qbitmap i dont know exactly what is that!

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

    Default Re: copy QPainter content to a QImage

    Quote Originally Posted by danics View Post
    you want me to casting paintingdevice?
    I'm asking you to look into the source code of the application you are maintaining and see what is the source device for the call being made.

    i m sure its not qwidget its qimage or qpixmap or qbitmap i dont know exactly what is that!
    So check. If it's QImage or QPixmap (or QBitmap which is its subclass) then you can use QImage::copy() or QPixmap::copy().
    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.


  12. #11
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: copy QPainter content to a QImage

    if i wanna do this i must check so much code, and change so many functions for referencing that object too, if i have only QPainterDevice i cannot do anything?

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

    Default Re: copy QPainter content to a QImage

    Quote Originally Posted by danics View Post
    if i wanna do this i must check so much code,
    Well, I'm sorry. The alternative is to rewrite the whole program from scratch. Use a search tool to help you.
    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.


Similar Threads

  1. QImage copy
    By paolom in forum Qt Programming
    Replies: 4
    Last Post: 10th February 2011, 05:59
  2. QPainter(&QPrinter) & QPainter(&QImage) communication
    By gufeatza in forum Qt Programming
    Replies: 2
    Last Post: 2nd February 2010, 07:25
  3. How to get the content of a QImage ?
    By fitzy in forum Qt Programming
    Replies: 4
    Last Post: 29th October 2009, 15:47
  4. how to copy QString content into array
    By eric in forum Qt Programming
    Replies: 12
    Last Post: 14th November 2007, 23:13
  5. copy-paste the content of a QTable
    By greencastor in forum Qt Programming
    Replies: 2
    Last Post: 13th September 2006, 12:20

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.