Unsolved How to capture the type of color and the type of drawing created with QPainter while I move the mouse (mouseEvent and eventFilter)
-
Hi everyone, can you help me with something that I can't solve ...
What I would like to solve is to capture the type of color and the type of drawing while I move the mouse over a drawing drawn and colored with QPainter.
It works like this:
virtual bool eventfilter(QObject *obj, QEvent *event)
{
If(event->type() == QEvent::MouseMove)
{
QMouseEvent mouseEvent = dynamic_cast<QMouseEvent>(event) ;If(mouseEvent)
{
qDebug() <<"x: "<<mouseEvent.x()<<"y:" <<mouseEvent.y();
}
}
}And this works for me by capturing the values of the x and y coordinate axis. But to capture the type of color and type of design drawn with QPainter .. I can't find a solution. Can you help me? Maybe you write me with some similar examples? Thanks a lot to those who will help me```
-
Hi
What do you mean with the type of color ?
like the RGB values?also "type of drawing" is also very broad.
What info you expect to get from QPainter that would help you say "what type"Can you give some examples ?
-
@mrjj
Hi, I mean the color RGB or red, green, yellow, etc.While for the type of drawing I intend to capture if it is a line, a rectangle, a triangle, etc.
For example, I draw a blue rectangle:
painter.setPen(QPen (Qt :: blue, 1)); painter.drawRect (1,1,10,10);
So when I hover the mouse over this design, it will have to indicate to me that it is a blue rectangle.
How do you create it in code? Thanks so much!
-
For color. You can paint on QImage instead.
It allows access to the pixels.
https://doc.qt.io/qt-5/qimage.html#pixelFor the type.
There is no way it can know you are over a blue rect as it just pixels for Qpainter.So for this to work, you have to keep track of the shapes you create and their locations.
Like for line the end points. for a rect, the rect etc. and for triangle the 3 points.Then you can loop this list to see if mouse is over any of the shapes and then you know the type that way.
To find rects, lines and triangles without keeping information would require some AI pattern recognition.
-
This post is deleted! -
Hi @mrjj ,
I try to understand on QImage. for now I have implemented it on QPicture and I don't know if you can capture the color type from QPicture functions. can you?
yes it is true the complexity of understanding what type of design it is, I thought there is an easy way to capture the type of design. maybe if anyone knows how to do it. would be very helpful.
thank you very much. I await other solutions