2

I need to check whether a QWidget exists in (x,y)

I use the following code:

QWidget *pObject = QApplication::widgetAt(mapToGlobal(QPoint(x, y)));

It works correctly when the window is normal; but when the window is minimized, it returns a wrong value...

How can I get correct value when the window is minimized?

5
  • I may be misunderstanding your question but when it is minimized you won't see it on the global map, right? so this would not work
    – Davlog
    Jun 5, 2014 at 14:27
  • Yes, you're right. In fact, i am writing a game like NS-SHAFT. I wanna use widgetAt to check the human whether stand on a stair. The following is my steps: 1. Obtain QWidget in (human.pos().x(), human.pos().y() + human.height()) 2. If there is a stair, human stand on it
    – 0140454
    Jun 5, 2014 at 14:38
  • In Qt Assistant, widgetAt says "Returns the widget at [ global ] screen position point, ..." In other words, does it exist a way to obtain QWidget in window map rather than global map? Sorry for my bad english.
    – 0140454
    Jun 5, 2014 at 14:55
  • Sorry I don't really know about those positions. But you can look at the functions from the qwidget class. Maybe there's a function you can use : qt-project.org/doc/qt-5/qwidget.html
    – Davlog
    Jun 5, 2014 at 15:55
  • Thanks @Davlog for reply :) You're right. The best solution is in QWidget member functions.
    – 0140454
    Jun 5, 2014 at 16:34

1 Answer 1

0

Your problem is that widgetAt() uses screen coordinates but in-fact your point doesn't lie on the screen when your application is minimized.

What you want is a mapping between the container widget and its content (child widget). This is provided by the childAt() function.

http://qt-project.org/doc/qt-4.8/qwidget.html#childAt

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.