PDA

View Full Version : Place Item At Mouse Coordinates?



steadi
14th October 2012, 21:42
Hello,

Thanks for the amount of support I have received on this forum so far, it is much appreciated as I have not used C++ for some time. Thanks to wysota, I have figured out custom classes and figured out a lot of my problems. I have run into another pretty simple problem and I was wondering if someone could help me out or point me in the right direction - When a user clicks on my graphics scene I would like it to place a blue square at the mouse position. How would I go about doing this?

I have the code for drawing the square but I do not have the code to place it at the mouse-coordinates.

Thanks in advance guys,
Matt

ottoshmidt
14th October 2012, 21:48
Check out QWidget::cursor() ,which returns QCursor and you can get .pos() from that. Also, you will probably have to look at QWidget::mapToGlobal() and/or QWidget::mapFromGlobal().

steadi
14th October 2012, 23:34
Hey Man, Thanks sooo much, I cannot begin to describe how much closer you have brought me to completing this. This works, however, the position is slightly off although this is more than likely because I need to look more into the mapFromGlobal()

Thanks,
Matt