Determining class of icon in Draggable Icons example
In the Draggable Icons examples, there is a mouse press event with this code:
Code:
{
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.
Re: Determining class of icon in Draggable Icons example
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?
Re: Determining class of icon in Draggable Icons example
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
Re: Determining class of icon in Draggable Icons example
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.