Results 1 to 4 of 4

Thread: initializing QPainter with a QImage

  1. #1
    Join Date
    Jul 2011
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default initializing QPainter with a QImage

    QPainter painter(&image);

    This is a line from one of the examples (Scribble) that comes with QT 4 Package.
    I tried to do the same in my app.

    QPainter painter(currentFrame->imgQ);
    (here currentFrame is an object of a class that contains the QImage imgQ)

    Now, when I do this, the error states that there is no any function that matches for my call.

    Can you please tell me how to initiate a QPainter with a QImage??
    Just so you know, my app is a webcam app and I want to add a feature where u can draw onto an image.

    Thanks already!!

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: initializing QPainter with a QImage

    Instead of trying things with trial and error, you should look into Qt's documentation for how things are suppused to work. In this case QPainter's class reference http://doc.qt.nokia.com/latest/qpainter.html states that it is contructed with a _pointer_ to a QPaintDevice, which a QImage is. Most likely the compiler's error message already told you all this.

  3. #3
    Join Date
    Jul 2011
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: initializing QPainter with a QImage

    Thanks... and sorry for looking like an ass here!! hehe

    I solved the problem. turns out it was a silly mistake.... I did not provide the QImage's address there (stupid me!!)

    anyways.... now I'v come across another problem.... Can you look at my paintEvent() function::

    void myApp:aintEvent(QPaintEvent *event){
    QPainter painter(imageLabel);
    QRect dirtyRect = event->rect();
    painter.drawImage(dirtyRect, currentFrame->imgQ, dirtyRect);

    }

    here, imageLabel is a QLabel inside myApp (which is a QMainWindow) . I have to paint a modified part of "currentFrame->imgQ" onto the imageLabel. when compiled, i get the error::

    QPainter::begin: Paint device returned engine == 0, type: 1

    Thanks again!!


    Added after 7 minutes:


    Okay.. I just had a lightbulb lit on my head. Is it because the paintEvent() doesnt belong to the QLabel?? If yes, how can i write a paintEvent() for this one imageLabel in particular!! (I dont want the paint Event to respond for other QLabels inside my app).....
    Last edited by Aayush; 18th July 2011 at 03:56.

  4. #4
    Join Date
    Sep 2011
    Posts
    2
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: initializing QPainter with a QImage

    Hello, i'am novice in QT. i try to add ScrollArea to the Scribble example of QT. Do you have idea how i can do that please.
    In ScribbleArea constructor i created imageLabel = new QLabel(this); and scrollArea = new QScrollArea(this); with scrollArea->setWidget(imageLabel);
    but I can display the scroll Area. Thank you for you cooperation

Similar Threads

  1. Replies: 0
    Last Post: 5th October 2010, 21:13
  2. QPainter/QImage/memory management error
    By p3l-outrepid in forum Qt Programming
    Replies: 0
    Last Post: 10th May 2010, 13:53
  3. QPainter(&QPrinter) & QPainter(&QImage) communication
    By gufeatza in forum Qt Programming
    Replies: 2
    Last Post: 2nd February 2010, 08:25
  4. QPainter doesn't seem to draw QImage
    By Denarius in forum Qt Programming
    Replies: 7
    Last Post: 3rd March 2009, 15:12
  5. QPainter and QImage
    By beerkg in forum Newbie
    Replies: 3
    Last Post: 7th September 2006, 15:48

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.