Results 1 to 2 of 2

Thread: Paint an image excluding a rect

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Paint an image excluding a rect

    Good morning,
    I have to color an image white without touching a specific internal area (an internal QRect contained in the image).
    How can I do it?
    Franco Amato

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Paint an image excluding a rect

    Copy the QRect region to a separate QImage (QImage::copy()), fill the original image with white (QImage::fill()), then use QPainter::drawImage() to copy the saved image back into place.

    You could also use clipping to define a clip path that excludes the rectangle (QPainter::setClipPath()) and then use QPainter::fillRect() to set the remainder to white. This will let you exclude non-rectangular regions, but it will probably be harder to get right.
    Last edited by d_stranz; 6th October 2022 at 18:50.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Painting one Image from another Image with paint brush
    By avanindra in forum Qt Programming
    Replies: 1
    Last Post: 21st July 2012, 13:08
  2. How can we paint image on slider?
    By pratik041 in forum Qt Programming
    Replies: 5
    Last Post: 9th November 2011, 19:17
  3. paint Rect sometimes missing one border
    By stella1016 in forum Qt Programming
    Replies: 5
    Last Post: 20th January 2011, 20:39
  4. Image format without bounding rect
    By dreamer in forum Qt Programming
    Replies: 5
    Last Post: 30th April 2008, 23:25
  5. Paint Rect visible on Drag to crop image coordinate
    By patrik08 in forum Qt Programming
    Replies: 8
    Last Post: 17th March 2007, 10:04

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.