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. Eye Dropper Implementation

Eye Dropper Implementation

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 742 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.
  • X Offline
    X Offline
    xtingray
    wrote on last edited by
    #1

    Hi,
    I need to implement the classic Eye Dropper tool for my application. The canvas is a QGraphicsView object and I wonder if there is a standard algorithm or procedure for this specific feature.
    Understanding that the Eye Dropper is a functionality required by almost any kind of graphic tool, I was expecting to find some example or reference, but I had no luck in my research.

    Any suggestion? Thanks.


    Qt Developer

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

      Hi,

      Not necessarily the most simple but you could render the widget under the tool to a QImage and then get the color from the pixel position using pixelColor.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      X 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        Not necessarily the most simple but you could render the widget under the tool to a QImage and then get the color from the pixel position using pixelColor.

        Hope it helps

        X Offline
        X Offline
        xtingray
        wrote on last edited by
        #3

        @SGaist Checking the documentation about QWidget: https://doc.qt.io/qt-5/qwidget.html#render
        Would it be possible to render just one pixel of the widget area? In that way, the procedure should be less demanding in terms of memory consumption. What do you think?


        Qt Developer

        X 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Based on the documentation, I think you can accomplish that using the QRegion parameter.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • X xtingray

            @SGaist Checking the documentation about QWidget: https://doc.qt.io/qt-5/qwidget.html#render
            Would it be possible to render just one pixel of the widget area? In that way, the procedure should be less demanding in terms of memory consumption. What do you think?

            X Offline
            X Offline
            xtingray
            wrote on last edited by
            #5

            Finally, I could find the piece of code I was looking for to implement an eye dropper tool:

            QColor QColorDialogPrivate::grabScreenColor(const QPoint &p)
            {
                const QDesktopWidget *desktop = QApplication::desktop();
                const QPixmap pixmap = QGuiApplication::primaryScreen()->grabWindow(desktop->winId(), p.x(), p.y(), 1, 1);
                QImage i = pixmap.toImage();
                return i.pixel(0, 0);
            }
            

            Qt Developer

            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