Esempio n. 1
0
 def paint(self, painter, option, index):
     """Overloads `paint` to draw borders"""
     QStyledItemDelegate.paint(self, painter, option, index)
     if index.data(BorderRole):
         painter.save()
         painter.setPen(index.data(BorderColorRole))
         rect = option.rect
         painter.drawLine(rect.topLeft(), rect.topRight())
         painter.restore()
Esempio n. 2
0
 def paint(self, painter, option, index):
     """Overloads `paint` to draw borders"""
     QStyledItemDelegate.paint(self, painter, option, index)
     borders = index.data(BorderRole)
     if borders:
         color = index.data(BorderColorRole) or self.color
         painter.save()
         painter.setPen(color)
         rect = option.rect
         for side, p1, p2 in (("t", rect.topLeft(), rect.topRight()),
                              ("r", rect.topRight(), rect.bottomRight()),
                              ("b", rect.bottomLeft(), rect.bottomRight()),
                              ("l", rect.topLeft(), rect.bottomLeft())):
             if side in borders:
                 painter.drawLine(p1, p2)
         painter.restore()
Esempio n. 3
0
 def paint(self, painter, option, index):
     """Overloads `paint` to draw borders"""
     QStyledItemDelegate.paint(self, painter, option, index)
     borders = index.data(BorderRole)
     if borders:
         color = index.data(BorderColorRole) or self.color
         painter.save()
         painter.setPen(color)
         rect = option.rect
         for side, p1, p2 in (("t", rect.topLeft(), rect.topRight()),
                              ("r", rect.topRight(), rect.bottomRight()),
                              ("b", rect.bottomLeft(), rect.bottomRight()),
                              ("l", rect.topLeft(), rect.bottomLeft())):
             if side in borders:
                 painter.drawLine(p1, p2)
         painter.restore()
Esempio n. 4
0
    def sizeHint(self, option, index):
        option = QStyleOptionViewItem(option)
        self.initStyleOption(option, index)
        size = QStyledItemDelegate.sizeHint(self, option, index)

        # TODO: get the default QMenu item height from the current style.
        size.setHeight(max(size.height(), 25))
        return size
 def sizeHint(self, option, index):
     size = QStyledItemDelegate.sizeHint(self, option, index)
     parent = self.parent()
     item = parent.itemFromIndex(index)
     widget = parent.itemWidget(item, 0)
     if widget:
         size = QSize(size.width(), widget.sizeHint().height() / 2)
     return size
 def sizeHint(self, option, index):
     size = QStyledItemDelegate.sizeHint(self,  option, index)
     parent = self.parent()
     item = parent.itemFromIndex(index)
     widget = parent.itemWidget(item, 0)
     if widget:
         size = QSize(size.width(), widget.sizeHint().height() / 2)
     return size
    def sizeHint(self, option, index):
        option = QStyleOptionViewItem(option)
        self.initStyleOption(option, index)
        size = QStyledItemDelegate.sizeHint(self, option, index)

        # TODO: get the default QMenu item height from the current style.
        size.setHeight(max(size.height(), 25))
        return size
Esempio n. 8
0
 def paint(self, painter, option, index):
     """
     Overloads paint and switches between orienting text vertically,
     painting borders, and drawing circles depending on indices.
     """
     if index.column() == 0 or index.row() == 1:
         gui.VerticalItemDelegate.paint(self, painter, option, index)
     elif index.column() == 1 or index.row() == 0:
         BorderedItemDelegate.paint(self, painter, option, index)
     else:
         QStyledItemDelegate.paint(self, painter, option, index)
         area = index.data(CircleAreaRole)
         rect = option.rect
         radius = max(1, self.max_diameter / 2 * sqrt(area))
         painter.setPen(Qt.transparent)
         painter.setBrush(Qt.blue)
         painter.setRenderHint(QPainter.Antialiasing)
         painter.drawEllipse(rect.center(), radius, radius)
 def sizeHint(self, option, index):
     """
     Overloads sizeHint and provides sizeHint for vertical text, cell with
     borders, or circles depending on indices.
     """
     if index.column() == 0 or index.row() == 1:
         return gui.VerticalItemDelegate.sizeHint(self, option, index)
     elif index.column() == 1 or index.row() == 0:
         return BorderedItemDelegate.sizeHint(self, option, index)
     else:
         return QStyledItemDelegate.sizeHint(self, option, index)
Esempio n. 10
0
 def test_qabstratitemview_item_delegate_for_index(self):
     view = QTableView()
     model = QStringListModel()
     model.setStringList(["AA", "BB"])
     view.setModel(model)
     idx1 = model.index(0, 0)
     idx2 = model.index(1, 0)
     delegate = QStyledItemDelegate()
     view.setItemDelegate(delegate)
     with warnings.catch_warnings(record=True):
         self.assertIs(view.itemDelegate(idx1), delegate)
         self.assertIs(view.itemDelegate(idx2), delegate)
Esempio n. 11
0
 def _on_distribution_color_changed(self):
     for ti in range(self.tabs.count()):
         widget = self.tabs.widget(ti)
         model = widget.model()
         while isinstance(model, QAbstractProxyModel):
             model = model.sourceModel()
         data = model.source
         class_var = data.domain.class_var
         if self.color_by_class and class_var and class_var.is_discrete:
             color_schema = [QColor(*c) for c in class_var.colors]
         else:
             color_schema = None
         if self.show_distributions:
             delegate = gui.TableBarItem(self, color=self.dist_color,
                                         color_schema=color_schema)
         else:
             delegate = QStyledItemDelegate(self)
         widget.setItemDelegate(delegate)
     tab = self.tabs.currentWidget()
     if tab:
         tab.reset()
Esempio n. 12
0
 def __init__(self, sortingModel, parent):
     QStyledItemDelegate.__init__(self, parent)
     self.sortingModel = sortingModel
Esempio n. 13
0
 def paint(self, painter, option, index):
     if index.column() == 0:
         option.textElideMode = Qt.ElideLeft
     elif index.column() == 2:
         option.textElideMode = Qt.ElideRight
     QStyledItemDelegate.paint(self, painter, option, index)
Esempio n. 14
0
    def _setup_table_view(self, view, data):
        """Setup the `view` (QTableView) with `data` (Orange.data.Table)
        """
        if data is None:
            view.setModel(None)
            return

        datamodel = RichTableModel(data)

        rowcount = data.approx_len()

        if self.color_by_class and data.domain.has_discrete_class:
            color_schema = [
                QColor(*c) for c in data.domain.class_var.colors]
        else:
            color_schema = None
        if self.show_distributions:
            view.setItemDelegate(
                gui.TableBarItem(
                    self, color=self.dist_color, color_schema=color_schema)
            )
        else:
            view.setItemDelegate(QStyledItemDelegate(self))

        # Enable/disable view sorting based on data's type
        view.setSortingEnabled(is_sortable(data))
        header = view.horizontalHeader()
        header.setSectionsClickable(is_sortable(data))
        header.setSortIndicatorShown(is_sortable(data))

        view.setModel(datamodel)

        vheader = view.verticalHeader()
        option = view.viewOptions()
        size = view.style().sizeFromContents(
            QStyle.CT_ItemViewItem, option,
            QSize(20, 20), view)

        vheader.setDefaultSectionSize(size.height() + 2)
        vheader.setMinimumSectionSize(5)
        vheader.setSectionResizeMode(QHeaderView.Fixed)

        # Limit the number of rows displayed in the QTableView
        # (workaround for QTBUG-18490 / QTBUG-28631)
        maxrows = (2 ** 31 - 1) // (vheader.defaultSectionSize() + 2)
        if rowcount > maxrows:
            sliceproxy = TableSliceProxy(
                parent=view, rowSlice=slice(0, maxrows))
            sliceproxy.setSourceModel(datamodel)
            # First reset the view (without this the header view retains
            # it's state - at this point invalid/broken)
            view.setModel(None)
            view.setModel(sliceproxy)

        assert view.model().rowCount() <= maxrows
        assert vheader.sectionSize(0) > 1 or datamodel.rowCount() == 0

        # update the header (attribute names)
        self._update_variable_labels(view)

        selmodel = BlockSelectionModel(
            view.model(), parent=view, selectBlocks=not self.select_rows)
        view.setSelectionModel(selmodel)
        view.selectionFinished.connect(self.update_selection)
Esempio n. 15
0
 def paint(self, painter, option, index):
     if index.column() == 0:
         option.textElideMode = Qt.ElideLeft
     elif index.column() == 2:
         option.textElideMode = Qt.ElideRight
     QStyledItemDelegate.paint(self, painter, option, index)
Esempio n. 16
0
 def __init__(self, ):
     QStyledItemDelegate.__init__(self, )
Esempio n. 17
0
 def sizeHint(self, option, index):
     size = QStyledItemDelegate.sizeHint(self, option, index)
     return QSize(size.width(), size.height() + 4)
Esempio n. 18
0
 def __init__(self, ):
     QStyledItemDelegate.__init__(self,)
Esempio n. 19
0
def init_style_option(
        delegate: QStyledItemDelegate,
        option: QStyleOptionViewItem,
        index: QModelIndex,
        data: Mapping[int, Any],
        roles: Optional[Container[int]] = None,
) -> None:
    """
    Like `QStyledItemDelegate.initStyleOption` but fill in the fields from
    `data` mapping. If `roles` is not `None` init the `option` for the
    specified `roles` only.
    """
    # pylint: disable=too-many-branches
    option.styleObject = None
    option.index = index
    if roles is None:
        roles = data
    features = 0
    if Qt.DisplayRole in roles:
        value = data.get(Qt.DisplayRole)
        if value is not None:
            option.text = delegate.displayText(value, option.locale)
            features |= _QStyleOptionViewItem_HasDisplay
    if Qt.FontRole in roles:
        value = data.get(Qt.FontRole)
        font = cast_(QFont, value)
        if font is not None:
            font = font.resolve(option.font)
            option.font = font
            option.fontMetrics = QFontMetrics(option.font)
    if Qt.ForegroundRole in roles:
        value = data.get(Qt.ForegroundRole)
        foreground = cast_(QBrush, value)
        if foreground is not None:
            option.palette.setBrush(QPalette.Text, foreground)
    if Qt.BackgroundRole in roles:
        value = data.get(Qt.BackgroundRole)
        background = cast_(QBrush, value)
        if background is not None:
            option.backgroundBrush = background
    if Qt.TextAlignmentRole in roles:
        value = data.get(Qt.TextAlignmentRole)
        alignment = cast_(int, value)
        if alignment is not None:
            alignment = alignment & _AlignmentMask
            option.displayAlignment = _AlignmentCache[alignment]
    if Qt.CheckStateRole in roles:
        state = data.get(Qt.CheckStateRole)
        if state is not None:
            features |= _QStyleOptionViewItem_HasCheckIndicator
            state = cast_(int, state)
            if state is not None:
                option.checkState = state
    if Qt.DecorationRole in roles:
        value = data.get(Qt.DecorationRole)
        if value is not None:
            features |= _QStyleOptionViewItem_HasDecoration
        if isinstance(value, QIcon):
            option.icon = value
        elif isinstance(value, QColor):
            pix = QPixmap(option.decorationSize)
            pix.fill(value)
            option.icon = QIcon(pix)
        elif isinstance(value, QPixmap):
            option.icon = QIcon(value)
            option.decorationSize = (value.size() / value.devicePixelRatio()).toSize()
        elif isinstance(value, QImage):
            pix = QPixmap.fromImage(value)
            option.icon = QIcon(value)
            option.decorationSize = (pix.size() / pix.devicePixelRatio()).toSize()
    option.features |= features
Esempio n. 20
0
 def __init__(self, sortingModel, parent):
     QStyledItemDelegate.__init__(self, parent)
     self.sortingModel = sortingModel
Esempio n. 21
0
 def __init__(self, parent=None):
     QStyledItemDelegate.__init__(self, parent)
Esempio n. 22
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
Esempio n. 23
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
Esempio n. 24
0
 def sizeHint(self, option, index):
     size = QStyledItemDelegate.sizeHint(self, option, index)
     return QSize(size.width(), size.height() + 4)
 def __init__(self, parent=None):
     QStyledItemDelegate.__init__(self, parent)