Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved Getting QPainter surface color at a specific point

    General and Desktop
    2
    4
    1166
    Loading More Posts
    • 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
      primem0ver last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 1
        • P
          primem0ver last edited by

          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.

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @primem0ver last edited by mrjj

            @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 Reply Quote 1
            • First post
              Last post