def set_selected_item(widget, idx):
 if (type(widget) is QtWidgets.QTreeWidget):
  item = widget.topLevelItem(idx)
  if item:
   item.setSelected(True)
   widget.setCurrentItem(item)

def set_selected_item ( widget , idx ) : if ( type ( widget ) is QtWidgets . QTreeWidget ) : item = widget . topLevelItem ( idx ) if item : item . setSelected ( True ) widget . setCurrentItem ( item )
sets a the currently selected item to the item at index idx .