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. Getting QPainter surface color at a specific point
Forum Updated to NodeBB v4.3 + New Features

Getting QPainter surface color at a specific point

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.6k Views 1 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.
  • P Offline
    P Offline
    primem0ver
    wrote on last edited by
    #1

    I want to dynamically color text on a custom drawn widget. The widget displays a grid of shapes of a potentially large number of colors along with data associated with the location of the shape and I want to test the color of an area (which can currently be determined by a single pixel) to decide whether to make the text white or black (based on average of the r, g, and b values).

    The problem is that QPainter doesn't seem to have a way to do this and since changes to the appearance of the widget can be animated to some degree (when scrolling or when zoom changes), I am worried that drawing to an image and copying the image will take too much processing time.

    Is there a way to directly get the color of a specific point on the QPainter surface? Or will I need to translate the point to screen coordinates and get the color using the OS API?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      What about just grabbing the area to a QImage and use
      the pixel functions from QImage?
      I assume you dont have to resample over and over?

      1 Reply Last reply
      1
      • P Offline
        P Offline
        primem0ver
        wrote on last edited by
        #3

        It's not a single text location. This is a repeating pattern, writing a data overlay (such as coordinates or some other value) for each cell (shape) in the picture. That would mean creating (allocating), copying, and destroying an average of 18,000 images every draw. That seems terribly time consuming.

        mrjjM 1 Reply Last reply
        0
        • P primem0ver

          It's not a single text location. This is a repeating pattern, writing a data overlay (such as coordinates or some other value) for each cell (shape) in the picture. That would mean creating (allocating), copying, and destroying an average of 18,000 images every draw. That seems terribly time consuming.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @primem0ver
          ok, i see. If drawing to QImage is too slow then
          maybe native api is fastest option.

          Im not aware of anything like
          HDC dc = GetWindowDC(NULL);
          COLORREF color = GetPixel(dc, _x _y );
          from Windows API, in Qt.

          1 Reply Last reply
          1

          • Login

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