Maxilys
26th February 2006, 17:15
Suppose I have QObject* obj and I know it's a widget, how can I obtain the QWidget* widget corresponding to obj?
const QToolBox* tb = (const QToolBox*) parent;
QObjectList *z = tb->queryList("QWidget", 0, FALSE, FALSE);
QObjectListIt it(*z);
QObject *obj;
int index = 0;
while ( (obj = it.current()) != 0 )
{
++it;
QRect tab = ( (QWidget*)obj )->rect();
if ( tab.contains(childRect.center()) )
{
index = tb->indexOf( (QWidget*)obj );
break;
}
}
delete z;
I don't know why but in this example ( (QWidget*)obj )->rect() works but indexOf( (QWidget*)obj ) doesn't. index is always -1. So I'm looking for something to replace (QWidget*)obj and obtain the correct result.
AFAIK the rest is OK and works as expected but if you see a flaw, don't hesitate to say so. I've spent so much time staring at this code that I can't see anything. :)
const QToolBox* tb = (const QToolBox*) parent;
QObjectList *z = tb->queryList("QWidget", 0, FALSE, FALSE);
QObjectListIt it(*z);
QObject *obj;
int index = 0;
while ( (obj = it.current()) != 0 )
{
++it;
QRect tab = ( (QWidget*)obj )->rect();
if ( tab.contains(childRect.center()) )
{
index = tb->indexOf( (QWidget*)obj );
break;
}
}
delete z;
I don't know why but in this example ( (QWidget*)obj )->rect() works but indexOf( (QWidget*)obj ) doesn't. index is always -1. So I'm looking for something to replace (QWidget*)obj and obtain the correct result.
AFAIK the rest is OK and works as expected but if you see a flaw, don't hesitate to say so. I've spent so much time staring at this code that I can't see anything. :)