PDA

View Full Version : Determining class of icon in Draggable Icons example



di_zou
14th October 2009, 22:38
In the Draggable Icons examples, there is a mouse press event with this code:


void DragWidget::mousePressEvent(QMouseEvent *event)
{
QLabel *child = static_cast<QLabel*>(childAt(event->pos()));
...
}


How would I change it so that I can determine what class the object childAt(event->pos()) is? I looked at the QWidget documentation, and I couldn't find a function similar to something like getClass() or getObjectType(). Any help would be appreciated.

jano_alex_es
15th October 2009, 09:01
I don't find anything either... what about setting a objectName (QObject property) each time you create a QWidget, or maybe setAccessibleDescription with the type?

Ginsengelf
15th October 2009, 09:41
Hi, if you have a limited number of possible classes, you can use QObject::qobject_cast for this. It returns zero if childAt(event->pos()) is not of the type you tried to cast it to.

Ginsengelf

axeljaeger
15th October 2009, 11:41
please do not an set object name.

Ask the childAt for its metaObject. It should answer all your question. There is className, inherits and so in the metaObject.