Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Painting into QImage with several layer vs one QImage (problem)
Qt 6.11 is out! See what's new in the release blog

Painting into QImage with several layer vs one QImage (problem)

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 318 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wanderer
    wrote on last edited by Wanderer
    #1

    Hello

    I followed Scrible example (painting into QImage) and it working fine when my brush is transparent. It works expected.
    Problem arise when I create another QImage (transparent) and paint into it and then draw both Qimage-s into widget. The "transparent behavior" is different then painting into one QImage, even if this one QImage is transparent.

    I wonder where can be problem?

    Here is code how I draw two images.

    void Little_Painter::paintEvent(QPaintEvent *event)
    {
        QPainter painter(this);
        QRect dRect = event->rect();
        painter.drawImage(dRect, m_image, dRect); 
        painter.drawImage(dRect, m_imageDraw, dRect); // m_imageDraw is transparent QImage
    }
    
    void Little_Painter::drawLineTo(const QPoint &endPoint)
    {
        QPainter painter(&m_imageDraw); // painting into m_imageDraw looks strange with very small transparency
        //QPainter painter(&m_image); // painting into m_image is ok
        painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
        QRect area;
        m_painterManager.draw(DrawManagerArgs(&painter, &endPoint, &area, &m_lastPoint, &m_measurePoint)); 
        update(area);
        undo_redo_system::setSActive(UndoRedoSpecialActiveArgs(&m_lastPoint));
        m_lastPoint = endPoint;
    }
    
    Little_Painter::Little_Painter(QWidget *parent) : QWidget(parent)
      , m_image(parent->size(), QImage::Format_RGBA8888_Premultiplied)
      , m_imageDraw(parent->size(), QImage::Format_RGBA8888_Premultiplied)
    // ....
    

    Look at the pictures:

    • top brush is how brush texture looks like and second two "round paintings" are transparent brush (left set on 2% and right on 1% transparency) and I painted around until I get it non-transparent in the middle.
      1. first picture is painting into QImage m_imageDraw
      1. picture is painting into QImage m_image without m_imageDraw
    1. picuture: (this looks interesting but it is not intention)
      TwoQImage.JPG

    2. second picture
      OneQImage.JPG

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved