title: What is the fastest way to get QWidget pixel color under mouse?
body: <p>I need to get the color of pixel under mouse, inside <code>mouseMoveEvent</code> of a QWidget (Breadboard). Currently I have this code-></p>
  
  <pre><code>void Breadboard::mouseMoveEvent(QMouseEvent *e)
  {
      QPixmap pixmap = QPixmap::grabWindow(winId());
      QRgb color = pixmap.toImage().pixel(e-&gt;x(), e-&gt;y());
      if (QColor(color) == terminalColor)
          QMessageBox::information(this, "Ter", "minal");
  }
  </code></pre>
  
  <p>Take a look at (scaled down) screenshot below-</p>
  
  <p><img src="https://i.stack.imgur.com/OUy1X.png" alt="enter image description here"></p>
  
  <p>When user moves his mouse on breadboard, the hole should get highlighted with some different color (like in red circle). And when the mouse exits, the previous color (grey) should be restored. So I need to do following steps- </p>
  
  <ol>
  <li>Get color under mouse</li>
  <li>According to color, floodfill the hole. (Different holes are distinguished using color)</li>
  <li>On mouse out, restore the color. There would be wires going over holes, so I can't update the small rectangle (hole) only.</li>
  </ol>
  
  <p>What is the fastest way of doing this? My attempt to extract color is not working i.e the Message box in my above code never displays. Moreover I doubt if my existing code is fast enough for my purpose. Remember, how fast you will be moving your mouse on breadboard.</p>
  
  <p>Note - I was able to do this using wxWidgets framework. But due to some issues that project got stalled. And I am rewriting it using Qt now.<br>
  You are invited to look at code <a href="https://github.com/vinayak-garg/dic-sim" rel="nofollow noreferrer">https://github.com/vinayak-garg/dic-sim</a> </p>