def METHOD_NAME(self, ontop):
    flags = self.windowFlags()
    if ontop:
        flags |= Qt.WindowStaysOnTopHint
    else:
        flags &= ~Qt.WindowStaysOnTopHint
    self.setWindowFlags(flags)
    self.show()