Results 1 to 11 of 11

Thread: Clearing a QLabel since the mouse position

  1. #1
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Clearing a QLabel since the mouse position

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Clearing a QLabel since the mouse position

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Clearing a QLabel since the mouse position

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Clearing a QLabel since the mouse position

    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??

  5. #5
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Clearing a QLabel since the mouse position

    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?

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Clearing a QLabel since the mouse position

    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....

  7. #7
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Clearing a QLabel since the mouse position

    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.
    Last edited by SkripT; 18th January 2006 at 17:22.

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Clearing a QLabel since the mouse position

    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...

  9. #9
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Clearing a QLabel since the mouse position

    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.

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Clearing a QLabel since the mouse position

    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.

  11. #11
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Clearing a QLabel since the mouse position

    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

Similar Threads

  1. Word at mouse click position in QGraphicsTextItem
    By pherthyl in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2008, 04:56
  2. Mouse position on screen
    By Nippler in forum Qt Programming
    Replies: 3
    Last Post: 7th August 2008, 14:22
  3. Position of text in a qlabel
    By jiveaxe in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2008, 13:26
  4. Enter event mouse position
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 7th May 2008, 18:53
  5. Qt4.1 Mouse Position & Scaling
    By Paul Drummond in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 19:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.