Beispiel #1
0
    def paint(self, painter, option, index):
        row = index.row()

        y = option.rect.y()
        if y <= 0:  # the first item got painted is always at top of list
            moved = abs(row - self._itemWidgetCacheHeadRow)
            if moved >= 1:
                scrollDown = row > self._itemWidgetCacheHeadRow
                if scrollDown:
                    self._freeWidgets.extend(self._itemWidgetCache[:moved])
                    del self._itemWidgetCache[:moved]
                else:
                    # can't determine which item become completely invisible
                    if moved >= len(
                            self._itemWidgetCache
                    ):  # moved so far that cached items are all useless
                        self._freeWidgets.extend(self._itemWidgetCache)
                        self._itemWidgetCache.clear()
                    else:
                        self._itemWidgetCache = [
                            None
                        ] * moved + self._itemWidgetCache
                self._itemWidgetCacheHeadRow = row
        elif y + option.rect.height(
        ) >= self._viewHeight:  # the last visible item
            # this hack can't recycle widget immediately after scrolled up
            while getattr(self._itemWidgetCache[-1], 'lastSetRow', -1) > row:
                self._freeWidgets.append(self._itemWidgetCache.pop())

        idx = row - self._itemWidgetCacheHeadRow

        if idx < len(self._itemWidgetCache):
            w = self._itemWidgetCache[idx]
        else:
            w = None
            self._itemWidgetCache.append(None)
        if w is None:
            recycled = self._freeWidgets.pop() if self._freeWidgets else None
            w = self.getItemWidget(index, row, recycled)

            self._itemWidgetCache[idx] = w
            w.lastSetRow = row

        w.resize(option.rect.size())
        properties = (bool(option.state & QStyle.State_Selected),
                      bool(option.state & QStyle.State_Active))
        if getattr(w, 'lastSetProperties', None) != properties:
            w.setProperty('selected', properties[0])
            w.setProperty('active', properties[1])
            w.lastSetProperties = properties
            refreshStyle(w)  # must be called after dynamic property changed

        # don't use offset argument of QWidget.render
        painter.translate(option.rect.topLeft())
        # render will activate layouts and send pending resize events
        w.render(painter, QPoint())
        painter.resetTransform()
Beispiel #2
0
    def paint(self, painter, option, index):
        row = index.row()

        y = option.rect.y()
        if y <= 0:  # the first item got painted is always at top of list
            moved = abs(row - self._itemWidgetCacheHeadRow)
            if moved >= 1:
                scrollDown = row > self._itemWidgetCacheHeadRow
                if scrollDown:
                    self._freeWidgets.extend(self._itemWidgetCache[:moved])
                    del self._itemWidgetCache[:moved]
                else:
                    # can't determine which item become completely invisible
                    if moved >= len(self._itemWidgetCache):  # moved so far that cached items are all useless
                        self._freeWidgets.extend(self._itemWidgetCache)
                        self._itemWidgetCache.clear()
                    else:
                        self._itemWidgetCache = [None] * moved + self._itemWidgetCache
                self._itemWidgetCacheHeadRow = row
        elif y + option.rect.height() >= self._viewHeight:  # the last visible item
            # this hack can't recycle widget immediately after scrolled up
            while getattr(self._itemWidgetCache[-1], 'lastSetRow', -1) > row:
                self._freeWidgets.append(self._itemWidgetCache.pop())

        idx = row - self._itemWidgetCacheHeadRow

        if idx < len(self._itemWidgetCache):
            w = self._itemWidgetCache[idx]
        else:
            w = None
            self._itemWidgetCache.append(None)
        if w is None:
            recycled = self._freeWidgets.pop() if self._freeWidgets else None
            w = self.getItemWidget(index, row, recycled)

            self._itemWidgetCache[idx] = w
            w.lastSetRow = row

        w.resize(option.rect.size())
        properties = (bool(option.state & QStyle.State_Selected),
                      bool(option.state & QStyle.State_Active))
        if getattr(w, 'lastSetProperties', None) != properties:
            w.setProperty('selected', properties[0])
            w.setProperty('active', properties[1])
            w.lastSetProperties = properties
            refreshStyle(w)  # must be called after dynamic property changed

        # don't use offset argument of QWidget.render
        painter.translate(option.rect.topLeft())
        # render will activate layouts and send pending resize events
        w.render(painter, QPoint())
        painter.resetTransform()
Beispiel #3
0
    def paint(self, painter, option, index):
        selected = bool(option.state & QStyle.State_Selected)
        active = bool(option.state & QStyle.State_Active)

        self._itemW.name.setText(index.data(Qt.DisplayRole))
        if self._countEnabled:
            countData = index.data(Qt.UserRole)
            self._itemW.count.setText(str(countData) if countData else '')
        self._itemW.setProperty('selected', selected)
        self._itemW.setProperty('active', active)
        refreshStyle(self._itemW)
        self._itemW.setFixedWidth(option.rect.width())

        painter.translate(option.rect.topLeft())
        self._itemW.render(painter, QPoint())
        painter.resetTransform()
Beispiel #4
0
 def setToolbarProperty(self):
     ex = settings['Main'].getboolean('extendTitleBarBg')
     self.toolBar.setProperty('extendTitleBar', ex)
     type_ = ''
     if ex:
         if isWin10:
             type_ = 'win10'  # system theme has no border
         elif isWin:
             type_ = 'win'
         else:
             type_ = 'other'
     self.toolBar.setProperty('titleBarBgType', type_)
     if self.isVisible():  # not being called by __init__
         refreshStyle(self.toolBar)
         refreshStyle(self.countLabel)  # why is this necessary?
         self._applyExtendTitleBarBg()
Beispiel #5
0
    def paint(self, painter, option, index):
        self._itemW.name.setText(index.data(Qt.DisplayRole))
        if self._countEnabled:
            self._itemW.count.setVisible(index.row() != 0)
            countData = index.data(Qt.UserRole)
            self._itemW.count.setText(str(countData) if countData else '')

        self._itemW.resize(option.rect.size())
        properties = (bool(option.state & QStyle.State_Selected),
                      bool(option.state & QStyle.State_Active))
        if getattr(self._itemW, 'lastSetProperties', None) != properties:
            self._itemW.setProperty('selected', properties[0])
            self._itemW.setProperty('active', properties[1])
            self._itemW.lastSetProperties = properties
            refreshStyle(self._itemW)  # must be called after dynamic property changed

        painter.translate(option.rect.topLeft())
        self._itemW.render(painter, QPoint())
        painter.resetTransform()