Find color of QRect
-
wrote on 2 Jan 2023, 22:29 last edited by
Can I find the color of a given QRect?
Please excuse me, if this is not how it generally works; I'm just starting out with Qt.
-
Can I find the color of a given QRect?
Please excuse me, if this is not how it generally works; I'm just starting out with Qt.
wrote on 2 Jan 2023, 22:39 last edited by@tim-hilt
AQRect
does not have a color, it is just the coordinates of a rectangle. Are you drawing/filling a rectangle somewhere?
https://www.bogotobogo.com/Qt/Qt5_QBrush_QRect.php explains rectangles and painting, might be of interest. -
wrote on 2 Jan 2023, 22:43 last edited by
thanks! I'll take a look at the link you provided.
-
wrote on 2 Jan 2023, 23:41 last edited by tim-hilt 1 Feb 2023, 23:41
@JonB is it right if I assume, that once an element is rendered, there is no way to get it's color again, if I'm not responsible for coloring it?
I used
QScreen::grabWindow
to get the color of a window but that only works if the window is not covered by another element. Is there a possibility to get colors for something on screen, even if it is covered? Somehow Qt has to know what to render, once the covering window is gone, right? -
wrote on 3 Jan 2023, 00:49 last edited by
In some cases it is possible to get the pixel value of an element. The mechanism is going to depend on what that element is. For example, QWidget::grab() facilitates retrieving a QPixMap, which can be converted to a QImage. The color of a pixel is retrievable via QImage::pixelColor(). That color isn't going to take into account any blending the windowing system is doing for transparency.
-
wrote on 3 Jan 2023, 02:22 last edited by Kent-Dorfman 1 Mar 2023, 02:24
haven't looked because I had no reason to use it, but some graphics APIs have a ValueOfPixel() function to get the attributes of an on-screen pixel. Seems of limited use though, since it is assumed that if you put down a pixel in the first place then you should know how you rendered it. FWIW, if your QPainter is rendering to a pixmap/bitmap then you should be able to get the rendered value from that backing.
3/6