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. Find color of QRect
Forum Updated to NodeBB v4.3 + New Features

Find color of QRect

Scheduled Pinned Locked Moved Unsolved General and Desktop
colorbeginnerrectangleqrect
6 Posts 4 Posters 1.0k Views 2 Watching
  • 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.
  • T Offline
    T Offline
    tim-hilt
    wrote on 2 Jan 2023, 22:29 last edited by
    #1

    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.

    J 1 Reply Last reply 2 Jan 2023, 22:39
    0
    • T tim-hilt
      2 Jan 2023, 22:29

      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.

      J Offline
      J Offline
      JonB
      wrote on 2 Jan 2023, 22:39 last edited by
      #2

      @tim-hilt
      A QRect 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.

      1 Reply Last reply
      2
      • T Offline
        T Offline
        tim-hilt
        wrote on 2 Jan 2023, 22:43 last edited by
        #3

        thanks! I'll take a look at the link you provided.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tim-hilt
          wrote on 2 Jan 2023, 23:41 last edited by tim-hilt 1 Feb 2023, 23:41
          #4

          @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?

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jeremy_k
            wrote on 3 Jan 2023, 00:49 last edited by
            #5

            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.

            Asking a question about code? http://eel.is/iso-c++/testcase/

            1 Reply Last reply
            0
            • K Offline
              K Offline
              Kent-Dorfman
              wrote on 3 Jan 2023, 02:22 last edited by Kent-Dorfman 1 Mar 2023, 02:24
              #6

              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.

              1 Reply Last reply
              0

              5/6

              3 Jan 2023, 00:49

              • Login

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