code: def qteIsQtmacsWidget(widgetObj):
      
      if widgetObj is None:
          return False
  
      if hasattr(widgetObj, '_qteAdmin'):
          return True
  
      # Keep track of the already visited objects to avoid infinite loops.
      visited = [widgetObj]
  
      # Traverse the hierarchy until a parent features the '_qteAdmin'
      # attribute, the parent is None, or the parent is an already
      # visited widget.
      wid = widgetObj.parent()
      while wid not in visited:
          if hasattr(wid, '_qteAdmin'):
              return True
          elif wid is None:
              return False
          else:
              visited.append(wid)
              wid = wid.parent()
      return False
docs: Determine if a widget is part of Qtmacs widget hierarchy.
  
      A widget belongs to the Qtmacs hierarchy if it, or one of its
      parents, has a "_qteAdmin" attribute (added via ``qteAddWidget``).
      Since every applet has this attribute is guaranteed that the
      function returns **True** if the widget is embedded inside
      somewhere.
  
      |Args|
  
      * ``widgetObj`` (**QWidget**): the widget to test.
  
      |Returns|
  
      * **bool**: **True** if the widget, or one of its ancestors
        in the Qt hierarchy have a '_qteAdmin' attribute.
  
      |Raises|
  
      * **None**