如题,我搜到了PyQt4的写法,想改成5的,但是5的函数变了,不太会,不知道5里鼠标处的Wid怎么获取?
这个是4的实现方法
PS:5不支持QPixmap.grabWindow,改成了Qscreen.grabWindow,
然后第一个参数Wid用QApplication.desktop().winId()也无法获取了,暂时还没有找到获取方式
if event.buttons() & Qt.LeftButton:
pointX = event.globalX()
pointY = event.globalY()
# img is QImage type
img = QPixmap.grabWindow(
QApplication.desktop().winId()).toImage()
rgb = img.pixel(pointX, pointY)
#十进制
red10 = QtGui.qRed(rgb)
green10 =QtGui.qGreen(rgb)
blue10 = QtGui.qBlue(rgb)
color10="("+str(red10)+","+str(green10)+","+str(blue10)+")"
#十六进制
#print str(hex(red10))
red16=str(hex(red10))[2:]
green16=str(hex(green10))[2]
blue16=str(hex(blue10))[2:]
color16=red16+green16+blue16
#print color16
print "(%s,%s) = %s (%s,%s,%s)" % (pointX, pointY, color16,red10, green10, blue10)
self.label.setText("(%s,%s) = %s (%s,%s,%s)" % (pointX, pointY, color16,red10, green10, blue10))
#该片段来自于http://outofmemory.cn
代码来源
http://outofmemory.cn/code-snippet/12666/PyQt4-get-screen-position-color