You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

sunny

Trainee

  • "sunny" is male
  • "sunny" started this thread

Posts: 53

Location: Bangalore

Occupation: Software Engg

  • Send private message

1

Wednesday, September 28th 2005, 10:36am

Name of widget where the mouse curser is.

Hi ,

At any instant how will I find out the mouse curser is on which widget.

Note : I would like to know the name of widget when the mouse is still (no mouse movement).

Regards,
Sunil
Sunny.

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

2

Wednesday, September 28th 2005, 10:49am

RE: Name of widget where the mouse curser is.

1. Enable mouse tracking, apply event filters to all widgets you wish to track, catch mouse enter and mouse move events (set a timer there) and emit signals with name of last entered widget on the timeout signal of a timer.

or

2. Enable mouse tracking, redefine mouse move event on the most parent widget to start a QTimer, connect to the timeout signal of the timer and check cursor position there and using QWidget::childAt find the widget under the cursor and emit a custom signal with its name.

3

Wednesday, September 28th 2005, 10:51am

Hi,

Try this,

For QT4:
QWidget *widget = qApp->widgetAt(QCursor::pos());
QString widget_name = widget->accessibleName();

For QT3:
QWidget *widget = qApp->widgetAt(QCursor::pos());
QString widget_name = widget->name();

Guilugi.

sunny

Trainee

  • "sunny" is male
  • "sunny" started this thread

Posts: 53

Location: Bangalore

Occupation: Software Engg

  • Send private message

4

Wednesday, September 28th 2005, 11:07am

Thanks a lot for this code !

For QT3:
QWidget *widget = qApp->widgetAt(QCursor::pos());
QString widget_name = widget->name();

My problem is solved.
:]
Sunny.

thahir1986

Beginner

  • "thahir1986" is male

Posts: 7

Location: Abu Dhabi

Occupation: Programmer

  • Send private message

5

Tuesday, October 26th 2010, 1:09pm

" For QT4:

QWidget *widget = qApp->widgetAt(QCursor::pos());

QString widget_name = widget->accessibleName();"


Thanks gferry..

I only got empty string for accessibleName(). Instead of that i used objectName() and got it. :thumbsup: