Reputation: 55472
I have created a custom Qt widget in Python and managed to get it to load into the form at runtime however when I try and use findChild to grab it back of the form instance I get None
back.
The widget is loaded and I can see it if I print out the names and objects on the form:
DEBUG:root:<PyQt4.QtGui.QCheckBox object at 0x11358030>
DEBUG:root:Near_Other_Infrastructure
DEBUG:root:<PyQt4.QtGui.QCheckBox object at 0x113582B8>
DEBUG:root:photo
DEBUG:root:<imagewidget.QMapImageWidget object at 0x113586A8>
This is the code:
images = self.forminstance.findChild(QMapImageWidget)
Update:
Seems doing this works:
images = self.forminstance.findChild(QWidget, "photo")
and it returns DEBUG:root:<imagewidget.QMapImageWidget object at 0x113586A8>
although I would really perfer to just get the control via the type without using the name.
Any ideas?
Upvotes: 1
Views: 1542
Reputation: 14815
I also had this problem.
One easy solution is to find a non-custom base class and cast.
Custom* ptr = dynamic_cast<QWidget*>(root->findChild<QWidget*>("MyWidgetName"));
if (ptr)
{
//...whatever
}
Upvotes: 0