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

Find color of QRect

Scheduled Pinned Locked Moved Unsolved General and Desktop
colorbeginnerrectangleqrect
6 Posts 4 Posters 1.0k 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.
  • tim-hiltT Offline
    tim-hiltT Offline
    tim-hilt
    wrote on 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.

    JonBJ 1 Reply Last reply
    0
    • tim-hiltT tim-hilt

      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.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on 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
      • tim-hiltT Offline
        tim-hiltT Offline
        tim-hilt
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • tim-hiltT Offline
          tim-hiltT Offline
          tim-hilt
          wrote on last edited by tim-hilt
          #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
          • jeremy_kJ Offline
            jeremy_kJ Offline
            jeremy_k
            wrote on 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
            • Kent-DorfmanK Offline
              Kent-DorfmanK Offline
              Kent-Dorfman
              wrote on last edited by Kent-Dorfman
              #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

              • Login

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