Expression painter:widget() returns the Qt object of class qt.QWidget underlying the painter. When the painter is not associated with a widget, this expression returns nil.
painter:widget()
qt.QWidget
nil