I want to know colors at my coordinates when i press mouse on canvasview or widget. how can i do?
i don't know all function to do that. Would you please give me some examples?![]()
I want to know colors at my coordinates when i press mouse on canvasview or widget. how can i do?
i don't know all function to do that. Would you please give me some examples?![]()
you could grab you widget and convert the pixmap into QImage. then you get the pixel under the mouse and get the color of the pixel. i don't know if it works, you have to try.
We tend not to do things this way. What exactly are you trying to achieve? If you use a canvas, you can access a pointer to the item under cursor and then you can often know the colour right away based on the item properties or you can implement your items in a smart way so that it can tell you what colour it has at a specified coordinate.
I am currently trying to implement the same thing only on a QGraphicsView. I have a question though, when you click on an item in the graphics view, what coordinates do you get? the coordinates of the image or the graphicsview's scene? i don't get it
Image Analysis Development Framework Using Qt (IADFUQ)
Depends how you access the coordinates, but mostly you will get scene coordinates.
A QGraphicsItem receives a QGraphicsSceneMouseEvent which has methods to get the position in any coordinates you want.
QGraphicsSceneMouseEvent::pos():
QGraphicsSceneMouseEvent::scenePos():Returns the mouse cursor position in item coordinates.
QGraphicsSceneMouseEvent::screenPos():Returns the mouse cursor position in scene coordinates.
The Graphics View Coordinate System docs explain the coordinate system in detailed level.Returns the mouse cursor position in screen coordinates.
J-P Nurmi
sincnarf (16th October 2007)
this is my code:
this code is one part of example: http://doc.trolltech.com/3.3/canvas-example.htmlQt Code:
{ QCanvasItemList l=canvas()->collisions(p); QCanvasItemList::Iterator it = l.begin(); ImageItem *item; for (it; it!=l.end(); ++it) { if ( (*it)->rtti() == imageRTTI ) { item = (ImageItem*)(*it); if ( !item->hit( p ) ) continue; } tmpPointEdit = p; moving = *it; moving_start = p; break; } int ix = tmpPointEdit.x(); int iy = tmpPointEdit.y(); QRgb newPixel = img -> pixel( ix, iy ); }To copy to clipboard, switch view to plain text mode
i have edited code in pressmouse method .
RUN:
+ First: i draw Rect with Red color on canvas. and use canvasview to show it.
+Second: i click on Rect. I want to get color at position when i press mouse. And save it into newPixel variable.
--> i wrong?
But could you answer the question why you want to know the colour of the pixel under cursor?
Bookmarks