Exemple #1
0
    def paintSection(self, painter, rect, logical_index):
        opt = QStyleOptionHeader()
        self.initStyleOption(opt)
        opt.rect = rect
        opt.section = logical_index
        opt.orientation = self.orientation()
        opt.textAlignment = Qt.AlignHCenter | Qt.AlignVCenter
        model = self.parent().model()
        opt.text = unicode(model.headerData(logical_index, opt.orientation, Qt.DisplayRole) or '')
        if self.isSortIndicatorShown() and self.sortIndicatorSection() == logical_index:
            opt.sortIndicator = QStyleOptionHeader.SortDown if self.sortIndicatorOrder() == Qt.AscendingOrder else QStyleOptionHeader.SortUp
        opt.text = opt.fontMetrics.elidedText(opt.text, Qt.ElideRight, rect.width() - 4)
        if self.isEnabled():
            opt.state |= QStyle.State_Enabled
            if self.window().isActiveWindow():
                opt.state |= QStyle.State_Active
                if self.hover == logical_index:
                    opt.state |= QStyle.State_MouseOver
        sm = self.selectionModel()
        if opt.orientation == Qt.Vertical:
            try:
                opt.icon = model.headerData(logical_index, opt.orientation, Qt.DecorationRole)
                opt.iconAlignment = Qt.AlignVCenter
            except (IndexError, ValueError, TypeError):
                pass
            if sm.isRowSelected(logical_index, QModelIndex()):
                opt.state |= QStyle.State_Sunken

        painter.save()
        if (
                (opt.orientation == Qt.Horizontal and sm.currentIndex().column() == logical_index) or
                (opt.orientation == Qt.Vertical and sm.currentIndex().row() == logical_index)):
            painter.setFont(self.current_font)
        self.style().drawControl(QStyle.CE_Header, opt, painter, self)
        painter.restore()
Exemple #2
0
    def paintSection(self, painter, rect, logical_index):
        opt = QStyleOptionHeader()
        self.initStyleOption(opt)
        opt.rect = rect
        opt.section = logical_index
        opt.orientation = self.orientation()
        opt.textAlignment = Qt.AlignHCenter | Qt.AlignVCenter
        model = self.parent().model()
        opt.text = unicode(model.headerData(logical_index, opt.orientation, Qt.DisplayRole) or '')
        if self.isSortIndicatorShown() and self.sortIndicatorSection() == logical_index:
            opt.sortIndicator = QStyleOptionHeader.SortDown if self.sortIndicatorOrder() == Qt.AscendingOrder else QStyleOptionHeader.SortUp
        opt.text = opt.fontMetrics.elidedText(opt.text, Qt.ElideRight, rect.width() - 4)
        if self.isEnabled():
            opt.state |= QStyle.State_Enabled
            if self.window().isActiveWindow():
                opt.state |= QStyle.State_Active
                if self.hover == logical_index:
                    opt.state |= QStyle.State_MouseOver
        sm = self.selectionModel()
        if opt.orientation == Qt.Vertical:
            try:
                opt.icon = model.headerData(logical_index, opt.orientation, Qt.DecorationRole)
                opt.iconAlignment = Qt.AlignVCenter
            except (IndexError, ValueError, TypeError):
                pass
            if sm.isRowSelected(logical_index, QModelIndex()):
                opt.state |= QStyle.State_Sunken

        painter.save()
        if (
                (opt.orientation == Qt.Horizontal and sm.currentIndex().column() == logical_index) or
                (opt.orientation == Qt.Vertical and sm.currentIndex().row() == logical_index)):
            painter.setFont(self.current_font)
        self.style().drawControl(QStyle.CE_Header, opt, painter, self)
        painter.restore()
Exemple #3
0
 def sectionSizeFromContents(self, logical_index):
     self.ensurePolished()
     opt = QStyleOptionHeader()
     self.initStyleOption(opt)
     opt.section = logical_index
     opt.orientation = self.orientation()
     opt.fontMetrics = self.fm
     model = self.parent().model()
     opt.text = unicode(model.headerData(logical_index, opt.orientation, Qt.DisplayRole) or '')
     if opt.orientation == Qt.Vertical:
         try:
             opt.icon = model.headerData(logical_index, opt.orientation, Qt.DecorationRole)
             opt.iconAlignment = Qt.AlignVCenter
         except (IndexError, ValueError, TypeError):
             pass
     if self.isSortIndicatorShown():
         opt.sortIndicator = QStyleOptionHeader.SortDown
     return self.style().sizeFromContents(QStyle.CT_HeaderSection, opt, QSize(), self)
Exemple #4
0
 def sectionSizeFromContents(self, logical_index):
     self.ensurePolished()
     opt = QStyleOptionHeader()
     self.initStyleOption(opt)
     opt.section = logical_index
     opt.orientation = self.orientation()
     opt.fontMetrics = self.fm
     model = self.parent().model()
     opt.text = unicode(model.headerData(logical_index, opt.orientation, Qt.DisplayRole) or '')
     if opt.orientation == Qt.Vertical:
         try:
             val = model.headerData(logical_index, opt.orientation, Qt.DecorationRole)
             if val is not None:
                 opt.icon = val
             opt.iconAlignment = Qt.AlignVCenter
         except (IndexError, ValueError, TypeError):
             pass
     if self.isSortIndicatorShown():
         opt.sortIndicator = QStyleOptionHeader.SortDown
     return self.style().sizeFromContents(QStyle.CT_HeaderSection, opt, QSize(), self)