Results 1 to 16 of 16

Thread: Draw over an image, without replacing the pixels, save drawn image as standalone

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2012
    Location
    India
    Posts
    102
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11
    Thanks
    4

    Default Re: Draw over an image, without replacing the pixels, save drawn image as standalone

    One more feature, sorry to extend in the same question but it's because the context has already been set.

    In order to implement scaling on the wheel event I did the following:

    Qt Code:
    1. void
    2. LT_DrawingCanvas::wheelEvent(QWheelEvent *event)
    3. {
    4. QWidget::wheelEvent(event);
    5. scaleFactor += ((float)event->delta()/1200.0);
    6. update();
    7. }
    To copy to clipboard, switch view to plain text mode 

    and in the paintEvent:

    Qt Code:
    1. void
    2. LT_DrawingCanvas::paintEvent(QPaintEvent *pe)
    3. {
    4. QPainter p(this);
    5. p.scale(scaleFactor, scaleFactor);
    6. p.drawPixmap(0, 0, m_base);
    7. p.drawImage(0, 0, m_mask);
    8. }
    To copy to clipboard, switch view to plain text mode 


    My widget hierarchy is as below:
    Mainwindow
    - Grid Layout
    - Scrollarea
    - MyCustomDrawing Canvas Widget (created just like the code wysota suggested above)

    I am not getting the scrollbars on scaling the image. I realize I am drawing the scaled image again, instead of resizing the widget. I tried using resize on the widget but it didn't work. What I am doing wrong ?

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

    Default Re: Draw over an image, without replacing the pixels, save drawn image as standalone

    Set the widgetResizable property of the scroll area to true.
    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. #3
    Join Date
    Mar 2012
    Location
    India
    Posts
    102
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11
    Thanks
    4

    Default Re: Draw over an image, without replacing the pixels, save drawn image as standalone

    Okay so for erasing I did the following, may be this will be useful to someone.

    Qt Code:
    1. QPainter painter(&m_mask);
    2. painter.setCompositionMode(QPainter::CompositionMode_Source);
    3. painter.setPen(QPen(QBrush(Qt::transparent), myPenWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
    To copy to clipboard, switch view to plain text mode 

    To understand the Composition Modes : http://doc.qt.io/qt-5/qpainter.html#...itionMode-enum


    Thanks.

    P.S.: Still working on the scrollarea stuff. Once done will update here.

  4. #4
    Join Date
    Oct 2014
    Posts
    81
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    20
    Thanked 9 Times in 9 Posts
    Wiki edits
    7

    Default Re: Draw over an image, without replacing the pixels, save drawn image as standalone

    I think it might be faster to use composition mode CLEAR. It erases whatever pixels are there.

Similar Threads

  1. Access the pixels of the Image(qml2)
    By stereoMatching in forum Qt Quick
    Replies: 1
    Last Post: 26th June 2013, 23:36
  2. Replies: 0
    Last Post: 9th July 2010, 14:06
  3. Draw Image into Pixmap/Image
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 19th May 2010, 06:56
  4. Replies: 6
    Last Post: 21st September 2009, 10:55
  5. Replacing One image with another
    By merry in forum Qt Tools
    Replies: 6
    Last Post: 8th February 2007, 13:22

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
  •  
Qt is a trademark of The Qt Company.