PDA

View Full Version : Clearing a QLabel since the mouse position



SkripT
18th January 2006, 17:37
Hi, i am making a photo editor using a QMainWindow. One of it's functions is draw the coordinates of the mouse respect the image in a QLabel placed at the status bar. If the mouse isn't under the surface of the image, the label is cleared. I want to know if there's a simpler way to know if the mouse is under the menu, tool or status bar than reimplementig the mouseMoveEvent of the main window. Thanks.

high_flyer
18th January 2006, 17:54
I want to know if there's a simpler way
Could you explain a bit more, or in other words what the problem is?
I really could not make out what the question is, so it could be others couldn't as well.

Cheers.

SkripT
18th January 2006, 18:03
The problem is that anytime that the mouse is out of the image surface the label has to be cleared. This means that if the mouse is under the menu bar, tool bar or status bar, the label has to be cleared. My question is if there's a way to do this better than reimplementig the mouseMoveEvent of the main window and check everytime if the current coordinates are under the image surface or not

high_flyer
18th January 2006, 18:08
My question is if there's a way to do this better than reimplementig the mouseMoveEvent of the main window...
Why not just keep track if QLabel has focus or not??

SkripT
18th January 2006, 18:11
Sorry my english is very poor and I don't know what you mean with

Why not just keep track if QLabel has focus or not??

Could you tell me the same in other words, please?

high_flyer
18th January 2006, 18:15
I don't know how simpler this can be said...
Do you know what a focus is?
If you do, then i suggested, that you update the QLabel with the cursor position only if the QLabel with the image has focus...

This was not a simpler answer, but I don't know how to put it simpler then that....

SkripT
18th January 2006, 18:20
Ok now I know what you want to say ;) But I thought that the focus was only for the keyboard and also I don't know if there's a signal emitted when the image loss the focus because it's when I clear the label.

high_flyer
18th January 2006, 18:34
You could grab mouse input, but that is not a good idea.
Well, then I don't see any better solution then to respond to mouseMoveEvent in the main window that hold the image QLabel.
But its not such a bad solution...

SkripT
18th January 2006, 18:48
The only problem that I see with this solution is that i test if the cursor is under the image everytime that the cursor moves.

high_flyer
18th January 2006, 18:54
why?
you mean if you move over the QLabel the mouseMoveEvnt of the main widget reacts?
I can't remember if this should be this way (in a way it could make sense if the QLabel is a child of the main windows but even then I doubt it should be like that), but if it is, then you can do the inverse thing, in stead of reacting to the mainWindow mouseMoveEvent you can react to the mouseMoveEvent of the QLabel.
Actually this is the best solution now that I think of it.

SkripT
18th January 2006, 19:23
The problem with this new solution that you suggest is that there's no way to know when the mouse isn't under the image surface and so the label is not cleared. I know it because is how I have implemented it now ;)