For all areas of the application that are not the 3D viewport, you can render the widget to an image in memory and then query the color under the cursor:
#------- globalPos = QtGui.QCursor.pos() widget = QtGui.QApplication.widgetAt(globalPos) img = QtGui.QImage(widget.size(), QtGui.QImage.Format_ARGB32) widget.render(img) pos = widget.mapFromGlobal(globalPos) color = QtGui.QColor.fromRgb(img.pixel(pos)) #------- But getting the color sample from the viewport is trickier because it is an OpenGL display and you have to use a different method (Maybe there is a better way than this): #------- import tempfile import maya.OpenMaya as om import maya.OpenMayaUI as mui tmp = tempfile.NamedTemporaryFile() globalPos = QtGui.QCursor.pos() widget = QtGui.QApplication.widgetAt(globalPos) view = mui.M3dView.active3dView() img = om.MImage() view.readColorBuffer(img, True) img.writeToFile(tmp.name, "png") qimg = QtGui.QImage(tmp.name) pos = widget.mapFromGlobal(globalPos) color = QtGui.QColor.fromRgb(qimg.pixel(pos)) #------- -- justin On Tue, Apr 8, 2014 at 3:35 AM, Marcus Ottosson <[email protected]>wrote: > Not sure about getting an arbitrary pixel regardless of what lies > underneath the cursor, but if your looking to eye-drop an image within a Qt > interface (which may be what the Render View is doing, I'm not sure), you > can get the cursor position with > QCursor.pos()<http://qt-project.org/doc/qt-5/qcursor.html#pos>and use that to > determine a color within an image using > QImage.pixel() <http://qt-project.org/doc/qt-4.8/qimage.html#pixel> > > # Psuedo-code > current_position = QCursor.pos() > widget_under_cursor = QApplication.widgetAt(current_position) > relative_position = widget_under_cursor.mapFromGlobal(current_position) > color = my_image.pixel(relative_position) # Returns a QRgb object > > > On 7 April 2014 16:20, Arvid Schneider <[email protected]> wrote: > >> Hey Group, >> >> I am trying to return rgb/float values at the current pixel under the >> mouse pointer. How would you accomplish that? >> The idea is, to press a button which enables the getColor method, so when >> I hover the mouse over mayas viewport (render view) and click MMB a >> rgb/float value is returned. >> I couldnt find a way yet using Qt or python. >> Maybe someone has an idea. >> Arvid >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Python Programming for Autodesk Maya" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/python_inside_maya/f31df7eb-d1af-4c40-8bc7-bc5e062c5553%40googlegroups.com<https://groups.google.com/d/msgid/python_inside_maya/f31df7eb-d1af-4c40-8bc7-bc5e062c5553%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > *Marcus Ottosson* > [email protected] > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAgR8Au7%2BhjnfYHHX4nWVfWkraZubrKon57_ywvWmmiiw%40mail.gmail.com<https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAgR8Au7%2BhjnfYHHX4nWVfWkraZubrKon57_ywvWmmiiw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2G_ua89AeugKvO0mqhczJENYmKa1sVSDd_2CVkQXNGWA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
