Results 1 to 4 of 4

Thread: Insert/Delete points over image

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2011
    Location
    Palma de Mallorca, Islas Baleares, Spain
    Posts
    24
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Question Insert/Delete points over image

    Hi!

    I'm working with the QT Example "image viewer". Now I open an image like this:

    Qt Code:
    1. QString fileName = QFileDialog::getOpenFileName(this,
    2. tr("Open File"), tr("C:"));
    3. if (!fileName.isEmpty()) {
    4. QImage image(fileName);
    5. if (image.isNull()) {
    6. QMessageBox::information(this, tr("Image Viewer"),
    7. tr("Cannot load %1.").arg(fileName));
    8. return;
    9. }
    10. imageLabel->setPixmap(QPixmap::fromImage(image));
    11. }
    To copy to clipboard, switch view to plain text mode 
    imageLabel is QLabel.

    Well, I want to draw something (circle, ellipse...) on the image every time I clicked (at mouse position). I have the mouse position (x, y). But I can't draw nothing. I would still see the image.

    What I've done?
    Qt Code:
    1. void SubQLabel::paintEvent(QPaintEvent *event){
    2. painter.begin(this);
    3. painter.setBackgroundMode(Qt::TransparentMode);
    4. painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
    5. painter.drawEllipse(10,10,10,10);
    6. painter.end();
    7. }
    To copy to clipboard, switch view to plain text mode 
    I subclased the QLabel I I override the paintEvent. But the image dissapears and it shows the Ellipse with white background.

    I would like to put a lot of points and delete this points on image.

    How can I do that?

    Thanks!!!!!

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Insert/Delete points over image

    But the image dissapears and it shows the Ellipse with white background.
    Because now the paintEvent() is only painting the ellipse.
    Add QLabel::paintEvent(event); before your drawing code.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    sergio87 (18th May 2011)

  4. #3
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert/Delete points over image

    try calling QLabel::Paint at the beginning of ur subclassed method

  5. The following user says thank you to pkj for this useful post:

    sergio87 (18th May 2011)

  6. #4
    Join Date
    Apr 2011
    Location
    Palma de Mallorca, Islas Baleares, Spain
    Posts
    24
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Insert/Delete points over image

    Thanks!!!

    It works!!. I'm going to try if I can draw an ellipse and then detele it. The code is:

    Qt Code:
    1. void SubQLabel::paintEvent(QPaintEvent *event){
    2. QLabel::paintEvent(event);
    3. painter.begin(this);
    4. painter.drawEllipse(10,10,10,10);
    5. painter.end();
    6. }
    To copy to clipboard, switch view to plain text mode 
    Painter is QPainter.

    Also I'm going to try how can I scale the ellipse at the same time I scale the image.

    Thank you very much!!!

Similar Threads

  1. Replies: 15
    Last Post: 8th June 2013, 06:15
  2. How to know not insert or delete query?
    By ramazangirgin in forum Qt Programming
    Replies: 2
    Last Post: 29th June 2010, 13:43
  3. How to insert an image through Qt
    By thanisha in forum Newbie
    Replies: 1
    Last Post: 26th June 2010, 05:55
  4. how can i mark points on top of a Image?
    By montamer in forum Qt Programming
    Replies: 2
    Last Post: 2nd April 2010, 12:53
  5. i need to know insert and delete methods in qsql for phone book application
    By gaurav purohit in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 15th September 2009, 14:04

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.