'Return the first num widget items with type cls.
This can be useful when for instance you need the first five search results.'

def get_first_items(self, num, cls=None):

    result = []
    for i in xrange(self.count()):
        widget_item = self.itemWidget(self.item(i))
        if ((not cls) or (cls and isinstance(widget_item, cls))):
            result.append(widget_item)
        if (len(result) >= num):
            break
    return result
