Results 1 to 8 of 8

Thread: Question about painting.

  1. #1
    Join Date
    Jul 2011
    Posts
    12
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Question about painting.

    Hi, I have the following dilemma.

    I have a picture that I need to be able to draw (and also write) on. I currently have managed to make a Qlabel and place the image on the label through pixmap. Ultimately I will need to print the (modified) image to a printer.

    So here is the question, is there any way to draw directly on the pixmap thats on the Qlabel, and if so how? I have tried googling but found nothing comprehensible.

    Thanks

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about painting.

    inherit from qlabel and implement your own paint event, or look into qgraphicsview/scene/item framework
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Jul 2011
    Posts
    12
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about painting.

    Unfortunately I have very little idea how to do those things, but thanks for trying.

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

    Default Re: Question about painting.

    Quote Originally Posted by Datakim View Post
    Unfortunately I have very little idea how to do those things, but thanks for trying.
    Hmm... so what exactly you were expecting?
    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.


  5. #5
    Join Date
    Jul 2011
    Posts
    12
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about painting.

    Quote Originally Posted by wysota View Post
    Hmm... so what exactly you were expecting?
    Basically, I have a jpg image. Lets call it image1.jpg. I have been trying to read information from google, and currently I have an ordinary Qlabel, to which I have managed to put the image1.jpg.

    However I need to be able to add text to that image. Basically I get text from a database, and I need to be able to write that text on the picture. The text itself changes depending on what line a user selects from the mysql database.

    I am rather inexperienced with QT, so despite trying many different solutions I have found on the net, I just cannot write text to the pixmap image on the label. In all cases I either get an error, nothing happens and in one case the image was just replaced with another blank pixmap.

    Ultimately I need to be able to print the (modified) image on paper.

    So if I wanted to load an image, and then write text to that (to specific coordinates on the image) how would I go about doing that. If someone could give me a quick example I would be truly gratefull. What would be the best and most simple way to do this: load image, show image, add text from database to specific coordinates in the image and finally print it out.

    Thanks

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

    Default Re: Question about painting.

    No no... I meant what kind of answer were you expecting to receive? "Use QLabel::doWhatDatakimWants(image)"? Writing your own classes and reimplementing virtual methods is basics of C++, you just have to learn it.
    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.


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

    Default Re: Question about painting.

    Quote Originally Posted by Datakim View Post
    Basically, I have a jpg image. Lets call it image1.jpg. I have been trying to read information from google, and currently I have an ordinary Qlabel, to which I have managed to put the image1.jpg.

    However I need to be able to add text to that image.
    But you don't need to add the text on the QLabel. You can keep the image in memory, add the text and then put it in the QLabel.

    1) Load the image file

    QImage picture(filename);

    ...create a QPainter for it:
    QPainter painter(&picture);

    ...Now you can do whatever to the image, before you put that into your label
    painter.drawText(...);
    (...)

    painter.end();

    label->setPixmap(QPixmap::fromImage(picture));

  8. The following user says thank you to mvuori for this useful post:

    Datakim (5th July 2012)

  9. #8
    Join Date
    Jul 2011
    Posts
    12
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about painting.

    Quote Originally Posted by mvuori View Post
    But you don't need to add the text on the QLabel. You can keep the image in memory, add the text and then put it in the QLabel.

    1) Load the image file

    QImage picture(filename);

    ...create a QPainter for it:
    QPainter painter(&picture);

    ...Now you can do whatever to the image, before you put that into your label
    painter.drawText(...);
    (...)

    painter.end();

    label->setPixmap(QPixmap::fromImage(picture));
    Thank you so much! That was exactly what I needed.

Similar Threads

  1. painting a compass
    By wagmare in forum Qt Programming
    Replies: 2
    Last Post: 15th November 2010, 07:16
  2. Regarding Painting
    By archanasubodh in forum General Programming
    Replies: 6
    Last Post: 8th August 2008, 18:23
  3. Gui Painting in Thread?
    By vishal.chauhan in forum Qt Programming
    Replies: 4
    Last Post: 24th July 2007, 09:24
  4. About painting
    By Pang in forum Qt Programming
    Replies: 3
    Last Post: 28th March 2007, 17:21
  5. painting raw u16 memory
    By stinos in forum Qt Programming
    Replies: 2
    Last Post: 6th September 2006, 09:45

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.