Exemplo n.º 1
0
    def paint(self, painter, option, index):
        painter.save()

        checked = index.model().data(index, Qt.UserRole)
        checkbox_indicator = QStyleOptionButton()

        #checkbox_indicator.state |= QStyle.State_Enabled

        if (index.flags() & Qt.ItemIsEditable) > 0:
            checkbox_indicator.state |= QStyle.State_Enabled
        else:
            checkbox_indicator.state |= QStyle.State_ReadOnly

        if checked:
            checkbox_indicator.state |= QStyle.State_On
        else:
            checkbox_indicator.state |= QStyle.State_Off

        checkbox_indicator.rect = QApplication.style().subElementRect(
            QStyle.SE_CheckBoxIndicator, checkbox_indicator, None)

        x = int(option.rect.center().x() - checkbox_indicator.rect.width() / 2)
        y = int(option.rect.center().y() -
                checkbox_indicator.rect.height() / 2)

        checkbox_indicator.rect.moveTo(x, y)

        if (option.state & QStyle.State_Selected):
            painter.fillRect(option.rect, option.palette.highlight())

        QApplication.style().drawControl(QStyle.CE_CheckBox,
                                         checkbox_indicator, painter)

        painter.restore()
    def paint(self, painter, option, index):
        painter.save()
        if not index.isValid():
            QSqlRelationalDelegate.paint(self, painter, option, index)

        if index.column() in self.__dates:
            value = QDate.fromString(index.model().data(index, Qt.DisplayRole),
                                     Qt.ISODate)
            value = value.toString(Qt.SystemLocaleLongDate)
            align = Qt.AlignHCenter | Qt.AlignVCenter
            if option.state and QStyle.State_Active:
                if option.state & QStyle.State_Selected:
                    palette = QPalette.HighlightedText
                else:
                    palette = QPalette.WindowText
            else:
                palette = QPalette.WindowText

            QApplication.style().drawItemText(painter, option.rect, align,
                                              option.palette, True, value,
                                              palette)
        else:
            QSqlRelationalDelegate.paint(self, painter, option, index)

        painter.restore()
Exemplo n.º 3
0
 def paint(self, painter, option, index):
     progressBar = None
     if pysideVersion == '1.2.2':
         progressBar = QStyleOptionProgressBarV2()
         progressBar.state = QStyle.State_Enabled
     else:
         progressBar = QStyleOptionProgressBar()
         progressBar.state = QStyle.State_Enabled
     progressBar.direction = QApplication.layoutDirection()
     progressBar.fontMetrics = QApplication.fontMetrics()
     progressBar.rect = option.rect
     progressBar.minimum = 0
     progressBar.maximum = 100
     progressBar.textAlignment = Qt.AlignCenter
     progressBar.textVisible = True
     dw = index.data()[0]
     tot = index.data()[1]
     if tot != 0:
         progressBar.progress = round(dw / tot * 100, 2)
     else:
         progressBar.progress = 0
     progressBar.text = "{} MB of {} MB".format(
         round(dw / (1024 * 1024), 2), round(tot / (1024 * 1024), 2))
     QApplication.style().drawControl(QStyle.CE_ProgressBar, progressBar,
                                      painter)
Exemplo n.º 4
0
    def paint(self, painter, option, index):
        if not self.draw_focus:
            option.state = option.state & (~QStyle.State_HasFocus)

        if not isinstance(index.data(), GraphRow):
            QStyledItemDelegate.paint(self, painter, option, index)
            return

        row = index.data()

        has_focus = option.state & QStyle.State_HasFocus
        option.state = option.state & (~QStyle.State_HasFocus)
        QStyledItemDelegate.paint(self, painter, option, index)

        lane_size = option.rect.height()

        painter.save()

        painter.setClipRect(option.rect)
        painter.translate(option.rect.x(), option.rect.y())
        painter.scale(lane_size, lane_size)
        painter.setRenderHint(QPainter.Antialiasing, True)

        max_lane = row.commit_node.lane

        if row.prev_row:
            for edge in row.prev_row.edges:
                max_lane = max(max_lane, edge.from_lane, edge.to_lane)
                self.draw_edge(painter, option, edge, -1)
        for edge in row.edges:
            max_lane = max(max_lane, edge.from_lane, edge.to_lane)
            self.draw_edge(painter, option, edge, 0)

        pen = QPen(Qt.black, self.node_thickness)
        painter.setPen(pen)
        painter.setBrush(option.palette.window())
        painter.drawEllipse(
            QPointF(row.commit_node.lane + 0.5, 0.5),
            self.node_radius, self.node_radius)

        if row.log_entry.refs:
            painter.resetTransform()
            painter.translate(
                option.rect.x() + (max_lane + 1) * lane_size,
                option.rect.y())

            ref_x = 0
            for ref in row.log_entry.refs:
                ref_x = self.draw_ref(painter, option, ref, row.repo, ref_x)

        painter.restore()

        if has_focus:
            painter.save()
            focus_option = QStyleOptionFocusRect()
            focus_option.rect = option.rect
            QApplication.style().drawPrimitive(QStyle.PE_FrameFocusRect,
                focus_option, painter)
            painter.restore()
Exemplo n.º 5
0
 def paint( self, painter, option, index ):
     super(VoxelGridDelegate,self).paint(painter, option, index)
     column = GridManagerColumns.Columns[index.column()]
     # The only change we present here, is a "fake" button (It is a button, but just in appearance),
     # to invoke the Color Picker Widget, in the Color column.
     if( column == GridManagerColumns.Color ):
         button = QStyleOptionButton() # It looks like a button, but similarities ends here. It's just a skin.
         button.rect = self._get_color_picker_button_dimensions(option.rect)
         button.text = "...";
         # By the way, I couldn't change the color of the f***ing button. So i decided to use the background of the cell as the indicator
         button.state = QStyle.State_Enabled
         QApplication.style().drawControl( QStyle.CE_PushButton, button, painter )
Exemplo n.º 6
0
    def paint(self, painter, option, index):
        '''
        Paint a checkbox without the label.
        '''

        value = index.model().data(index, Qt.DisplayRole)

        if value == None:
            return
        # we draw the background

        cg = QPalette.Disabled
        if option.state & QStyle.State_Enabled:
            cg = QPalette.Normal
            if not (option.state & QStyle.State_Active):
                cg = QPalette.Inactive

        r = QRect(option.rect.x(),option.rect.y(),option.rect.width(),option.rect.height())
        if option.state & QStyle.State_Selected:
            painter.fillRect(option.rect, option.palette.color(cg, QPalette.Highlight))
        elif index.data(Qt.BackgroundRole):
            # Alternating background color for the rows, to improve
            # readability
            # if index.row() % 2 == 1:
            #    painter.fillRect(option.rect, QColor(240,240,255))
            painter.fillRect(option.rect, index.data(Qt.BackgroundRole))
        else:
            painter.fillRect(option.rect, Qt.GlobalColor.white)

        checked = bool(index.model().data(index, Qt.DisplayRole))
        check_box_style_option = QStyleOptionButton()

        if (index.flags() & Qt.ItemIsEditable) > 0:
            check_box_style_option.state |= QStyle.State_Enabled
        else:
            check_box_style_option.state |= QStyle.State_ReadOnly

        if checked:
            check_box_style_option.state |= QStyle.State_On
        else:
            check_box_style_option.state |= QStyle.State_Off

        check_box_style_option.rect = self.getCheckBoxRect(option)

        # if not index.model().hasFlag(index, Qt.ItemIsEditable):
        if not ((index.flags() & Qt.ItemIsEditable) > 0):
             check_box_style_option.state |= QStyle.State_ReadOnly

        QApplication.style().drawControl(QStyle.CE_CheckBox, check_box_style_option, painter)
 def checkBoxRect(self, opt, editor):
     cb_option = QStyleOptionButton()
     style = QApplication.style()
     cb_rect = style.subElementRect(QStyle.SE_CheckBoxIndicator, cb_option,
         editor)
     cb_point = QPoint(opt.rect.x() + (opt.rect.width() - cb_rect.width()) / 2,
         opt.rect.y() + (opt.rect.height() - cb_rect.height()) / 2)
     return QRect(cb_point, cb_rect.size())
 def checkBoxRect(self, opt, editor):
     cb_option = QStyleOptionButton()
     style = QApplication.style()
     cb_rect = style.subElementRect(QStyle.SE_CheckBoxIndicator, cb_option,
                                    editor)
     cb_point = QPoint(
         opt.rect.x() + (opt.rect.width() - cb_rect.width()) / 2,
         opt.rect.y() + (opt.rect.height() - cb_rect.height()) / 2)
     return QRect(cb_point, cb_rect.size())
Exemplo n.º 9
0
def wraith():
    matplotlib.rcParams['mathtext.fontset'] = 'stixsans'
    app = QCoreApplication.instance()
    app.form = Form()
    #style choices common to both modes
    QApplication.setStyle(QStyleFactory.create('Plastique'))
    QApplication.setPalette(QApplication.style().standardPalette())
    #do it
    app.form.show()
Exemplo n.º 10
0
    def paintEvent(self, event):
        super(FilterEditor, self).paintEvent(event)
        if not self.text(): return
        option = QStyleOption()
        option.rect = self.glyph_rect
        painter = QPainter(self)
        style = QApplication.style()

        style.drawPrimitive(QStyle.PE_IndicatorTabClose, option, painter)
Exemplo n.º 11
0
 def __init__(self, parent=None):
     super(FilterEditor, self).__init__(parent=parent)
     style = QApplication.style()
     self.glyph_width = style.pixelMetric(QStyle.PM_TabCloseIndicatorWidth)
     self.glyph_height = style.pixelMetric(QStyle.PM_TabCloseIndicatorHeight)
     self.frame_width = style.pixelMetric(QStyle.PM_DefaultFrameWidth)
     self.hovering = False
     self.old_cursor = None
     self.setTextMargins(0, 0, self.glyph_width + self.frame_width, 0)
Exemplo n.º 12
0
    def _resize_view(self):
        """Set the QWebView's minimum height based on its current
        contents.

        """
        div = self.view.page().mainFrame().findFirstElement('.output')
        scrollbar_width = QApplication.style().pixelMetric(
            QStyle.PM_ScrollBarExtent)
        self.view.setMaximumHeight(
            div.geometry().height() + scrollbar_width + 16)
Exemplo n.º 13
0
 def getCheckBoxRect(self, option):
     check_box_style_option = QStyleOptionButton()
     check_box_rect = QApplication.style().subElementRect(
         QStyle.SE_CheckBoxIndicator, check_box_style_option, None)
     check_box_point = QPoint(
         option.rect.x() + option.rect.width() / 2 -
         check_box_rect.width() / 2,
         option.rect.y() + option.rect.height() / 2 -
         check_box_rect.height() / 2)
     return QRect(check_box_point, check_box_rect.size())
Exemplo n.º 14
0
def main():
    matplotlib.rcParams['mathtext.fontset'] = 'stixsans'
    app = QApplication(sys.argv)
    form = Form()
    #style choices common to both modes
    QApplication.setStyle(QStyleFactory.create('Plastique'))
    QApplication.setPalette(QApplication.style().standardPalette())
    #do it
    form.show()
    app.exec_()
Exemplo n.º 15
0
    def paint(self, painter, option, index):
        checked = bool(index.data())
        check_box_style_option = QStyleOptionButton()

        if (index.flags() & Qt.ItemIsEditable) > 0:
            check_box_style_option.state |= QStyle.State_Enabled
        else:
            check_box_style_option.state |= QStyle.State_ReadOnly

        if checked:
            check_box_style_option.state |= QStyle.State_On
        else:
            check_box_style_option.state |= QStyle.State_Off

        check_box_style_option.rect = self.getCheckBoxRect(option)

        check_box_style_option.state |= QStyle.State_Enabled

        QApplication.style().drawControl(QStyle.CE_CheckBox,
                                         check_box_style_option, painter)
Exemplo n.º 16
0
    def drawBackground(self, painter, option, index):
        """Draw the background only of a styled item"""
        opt = QStyleOptionViewItemV4(option)
        self.initStyleOption(opt, index)

        if opt.widget is None:
            style = QApplication.style()
        else:
            style = opt.widget.style()

        style.drawPrimitive(QStyle.PE_PanelItemViewItem, opt, painter, opt.widget)
Exemplo n.º 17
0
 def data(self, index, role):
     if not index.isValid():
         return None
     item = model_item(index)
     if role == Qt.DisplayRole:
         if isinstance(item, Repo):
             return item.os_path
         return item.name or item.os_path
     if role == Qt.DecorationRole:
         if index.column() > 0:
             return None
         return QApplication.style().standardIcon(QStyle.SP_DirIcon)
Exemplo n.º 18
0
 def create_ui(self):
     super(FileView, self).create_ui()
     self.toggle_deep_button.setIcon(QApplication.style().standardIcon(
         QStyle.SP_DirIcon))
     self.toggle_deep_button.toggled.connect(self.deep_toggled)
     self.toggle_unmodified_button.setIcon(apply_status_to_icon(
         QApplication.style().standardIcon(QStyle.SP_FileIcon),
         git_api.UNMODIFIED, git_api.UNMODIFIED))
     self.toggle_unmodified_button.toggled.connect(self.toggle_filter(
         exclude_unmodified))
     self.toggle_untracked_button.setIcon(apply_status_to_icon(
         QApplication.style().standardIcon(QStyle.SP_FileIcon),
         git_api.UNTRACKED, git_api.UNTRACKED))
     self.toggle_untracked_button.toggled.connect(self.toggle_filter(
         exclude_untracked))
     self.toggle_ignored_button.setIcon(apply_status_to_icon(
         QApplication.style().standardIcon(QStyle.SP_FileIcon),
         git_api.IGNORED, git_api.IGNORED))
     self.toggle_ignored_button.toggled.connect(self.toggle_filter(
         exclude_ignored))
     self.filter_text.textEdited.connect(self.filter_text_edited)
     workspace = self.app.workspace
     self._directory = None
     self._file_lister = shallow_file_list
     self.file_model = FileModel(workspace, parent=self)
     self.file_model.file_source = lambda: (self._file_lister(self._directory)
         if self._directory else None)
     self.filter_model = FilterModel(parent=self)
     self.filter_model.setSourceModel(self.file_model)
     self.file_list.setModel(self.filter_model)
     # We must assign the selection model to a variable, to avoid triggering
     # a segfault bug (temporary PyObject* destroyed prematurely)
     # see https://bugreports.qt-project.org/browse/PYSIDE-79
     selection_model = self.file_list.selectionModel()
     selection_model.currentChanged.connect(self.current_item_changed)
     selection_model.selectionChanged.connect(self.item_selection_changed)
     self.app.view_focus_out[self] += self.lost_focus
     self.app.view_focus_in[self] += self.gained_focus
Exemplo n.º 19
0
 def __init__(self, parent=None):
     QApplication.setStyle(QStyleFactory.create("Plastique"))
     QApplication.setPalette(QApplication.style().standardPalette())
     super(MainWindow, self).__init__(None)  
     centralwidget = QWidget(self)
     self.setCentralWidget(centralwidget)
     self.layout = QVBoxLayout(centralwidget)
     
     button = QPushButton("Set WSDL Address")
     button.clicked.connect(self.request_wsdl)
     self.layout.addWidget(button)
     
     self.toolbox = QToolBox()
     self.layout.addWidget(self.toolbox)
     self.url = ""
    def paint(self, painter, option, index):
        painter.save()
        if not index.isValid():
            QSqlRelationalDelegate.paint(self, painter, option, index)

        if index.column() in self.__dates:
            value = QDate.fromString(index.model().data(index, Qt.DisplayRole),
                 Qt.ISODate)
            value = value.toString(Qt.SystemLocaleLongDate)
            align = Qt.AlignHCenter | Qt.AlignVCenter
            if option.state and QStyle.State_Active:
                if option.state & QStyle.State_Selected:
                    palette = QPalette.HighlightedText
                else:
                    palette = QPalette.WindowText
            else:
                palette = QPalette.WindowText

            QApplication.style().drawItemText(painter, option.rect, align,
                option.palette, True, value, palette)
        else:
            QSqlRelationalDelegate.paint(self, painter, option, index)

        painter.restore()
Exemplo n.º 21
0
    def paint(self, painter, option, index):
        """Re-implementation from QStyledItemDelegate, calls filter()"""
        opt = QStyleOptionViewItemV4(option)
        self.initStyleOption(opt, index)

        # Filter the Style Option View Item
        opt_ = self.filter(opt, index)
        if opt_ and isinstance(opt_, QStyleOptionViewItem):
            opt = opt_

        # Draw the item view
        if opt.widget is None:
            style = QApplication.style()
        else:
            style = opt.widget.style()

        style.drawControl(QStyle.CE_ItemViewItem, opt, painter, opt.widget)
    def paint(self, painter, option, index):

        icon = index.data(ItemUserRole.IconRole)
        if (not icon) or icon.isNull():
            return QStyledItemDelegate.paint(self, painter, option, index)

        opt = QStyleOptionViewItemV4(option)
        self.initStyleOption(opt, index)

        widget = opt.widget
        style = widget.style() if widget else QApplication.style()
        style.drawControl(QStyle.CE_ItemViewItem, opt, painter, widget)

        optState = opt.state
        mode = QIcon.Normal
        if (not (optState & QStyle.State_Enabled)):
            mode = QIcon.Disabled
        elif (optState & QStyle.State_Selected):
            mode = QIcon.Selected
        state = QIcon.On if (optState & QStyle.State_Open) else QIcon.Off

        decorSize = opt.decorationSize
        iconSize = icon.actualSize(decorSize, mode, state)
        iconHeight = iconSize.height()
        iconWidth = iconSize.width()

        iconRect = style.subElementRect(QStyle.SE_ItemViewItemDecoration, opt,
                                        widget)

        decorHeight = decorSize.height()
        decorWidth = decorSize.width()
        wadj = hadj = 0

        if iconHeight < decorHeight:
            hadj = (decorHeight - iconHeight) * .5

        if iconWidth < decorWidth:
            wadj = (decorWidth - iconWidth) * .5

        if wadj or hadj:
            iconRect.adjust(wadj, hadj, -wadj, -hadj)

        icon.paint(painter, iconRect, opt.decorationAlignment, mode, state)
    def paint(self, painter, option, index):

        icon = index.data(ItemUserRole.IconRole)
        if (not icon) or icon.isNull():
            return QStyledItemDelegate.paint(self, painter, option, index)

        opt = QStyleOptionViewItemV4(option)
        self.initStyleOption(opt, index)

        widget = opt.widget
        style = widget.style() if widget else QApplication.style()
        style.drawControl(QStyle.CE_ItemViewItem, opt, painter, widget)

        optState = opt.state
        mode = QIcon.Normal
        if (not (optState & QStyle.State_Enabled)):
            mode = QIcon.Disabled
        elif (optState & QStyle.State_Selected):
            mode = QIcon.Selected;
        state = QIcon.On if (optState & QStyle.State_Open) else QIcon.Off

        decorSize = opt.decorationSize
        iconSize = icon.actualSize(decorSize, mode, state)
        iconHeight = iconSize.height()
        iconWidth = iconSize.width()

        iconRect = style.subElementRect(QStyle.SE_ItemViewItemDecoration, opt, widget)

        decorHeight = decorSize.height()
        decorWidth = decorSize.width()
        wadj = hadj = 0

        if iconHeight < decorHeight:
            hadj = (decorHeight - iconHeight) * .5

        if iconWidth < decorWidth:
            wadj = (decorWidth - iconWidth) * .5

        if wadj or hadj:
            iconRect.adjust(wadj, hadj, -wadj, -hadj)

        icon.paint(painter, iconRect, opt.decorationAlignment, mode, state)
Exemplo n.º 24
0
 def make_source(self, name):
     self.compiler_view.addItem(name)
     self.compiler_view.setCurrentRow(0)
     scrollbar_width = QApplication.style().pixelMetric(
         QStyle.PM_ScrollBarExtent)
     self.compiler_view.setMaximumWidth(
         self.compiler_view.sizeHintForColumn(0) + scrollbar_width + 16)
     page = QWidget()
     QHBoxLayout(page)
     page.layout().setContentsMargins(*(0,) * 4)
     source = QTextEdit()
     source.setStyleSheet('min-width: 0; min-height: 0')
     source.setReadOnly(True)
     QVBoxLayout(source)
     button = QPushButton('Copy')
     button.clicked.connect(functools.partial(self.set_clipboard, source))
     page.layout().addWidget(source)
     source.layout().addWidget(button, 0, Qt.AlignRight | Qt.AlignBottom)
     self.stacked_widget.addWidget(page)
     return source
Exemplo n.º 25
0
    def paint(self, painter, option, index):
        """QStyledItemDelegate.paint implementation
        """
        option.state &= ~QStyle.State_HasFocus  # never draw focus rect
        
        options = QStyleOptionViewItemV4(option)
        self.initStyleOption(options,index)

        style = QApplication.style() if options.widget is None else options.widget.style()

        doc = QTextDocument()
        doc.setDocumentMargin(1)
        doc.setHtml(options.text)
        if options.widget is not None:
            doc.setDefaultFont(options.widget.font())
        #  bad long (multiline) strings processing doc.setTextWidth(options.rect.width())

        options.text = ""
        style.drawControl(QStyle.CE_ItemViewItem, options, painter)

        ctx = QAbstractTextDocumentLayout.PaintContext()

        # Highlighting text if item is selected
        if option.state & QStyle.State_Selected:
            ctx.palette.setColor(QPalette.Text, option.palette.color(QPalette.Active, QPalette.HighlightedText))

        textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
        painter.save()
        painter.translate(textRect.topLeft())
        """Original example contained line
            painter.setClipRect(textRect.translated(-textRect.topLeft()))
        but text is drawn clipped with it on kubuntu 12.04
        """
        doc.documentLayout().draw(painter, ctx)

        painter.restore()
Exemplo n.º 26
0
    def paint(self, painter, option, index):
        """
        Re-implementation of the paint method. 
        This will render a stream item that contains an icon, the name, 
        a description, the game being played, and a dropdown menu.
        """
        super(StreamItemDelegate, self).paint(painter, option, index)
        stream = index.data()

        if option.state & QStyle.State_MouseOver:
            painter.fillRect(option.rect, option.palette.color(QPalette.Highlight))
            painter.setPen(Qt.white)
        else:
            painter.setPen(Qt.black)

        # I'll have a rectangle pls.
        r = option.rect

        # Draw the Service icon (Twitch, etc)
        icon = get_service_icon(stream.service)
        icon_size = 16
        icon_offset = (r.height()/2) - (icon_size/2)
        if stream.status == 0: #offline
            icon.paint(painter, r.left()+10, r.top()+icon_offset, icon_size, icon_size, Qt.AlignLeft | Qt.AlignVCenter, mode=QIcon.Disabled) 
        else:
            icon.paint(painter, r.left()+10, r.top()+icon_offset, icon_size, icon_size, Qt.AlignLeft | Qt.AlignVCenter, mode=QIcon.Normal) 

        # Paint the stream name
        painter.drawText(r.left()+40, r.top()-8, r.width(), r.height(), Qt.AlignVCenter | Qt.AlignLeft, stream.name)

        # Paint the game name, if any.
        painter.save()
        name_len = painter.fontMetrics().width(stream.name)
        font = painter.font()
        font.setPixelSize(9)
        font.setItalic(True)
        painter.setFont(font)
        painter.setPen(QColor(*get_game_colour(stream.game)))
        # Position of the left edge + the length of the name text + the offset of the stream name + an additional offset for padding.
        painter.drawText((r.left()+name_len)+40, r.top()-8, r.width(), r.height(), Qt.AlignVCenter | Qt.AlignLeft, stream.game)
        painter.restore()

        # Paint a dropdown button for options.
        x1 = 50; y1 = 8; iw = 9; ih = 6; 
        orect = r.adjusted(name_len+x1, y1, -(r.width()-(name_len+x1+iw)), -(r.height()-(y1+ih))) # Rectangle to store the dropdown icon
        hrect = orect.adjusted(-4, -3, 6, 5) # Rectangle to hover within.
        hbg = orect.adjusted(-2, -1, 2, 1) # Rectangle to draw the rounded background in
        options_button = QStyleOptionButton()
        # Cursor must be translated to relative positioning via the parent widget, note that is this is not a widget.
        if hrect.contains(self.parent.mapFromGlobal(QCursor.pos())):
            # Hover event for the dropdown options button
            options_button.icon = self.icons["down_hover"]
            # Draw a background behind the icon
            painter.save()
            painter.setRenderHints(painter.Antialiasing | painter.HighQualityAntialiasing)
            painter.setPen(QPen(QColor(101, 99, 98)))
            painter.setBrush(QBrush(QColor(101, 99, 98)))
            painter.drawRoundRect(QRectF(hbg), 10.0, 5.0)
            painter.restore()
        else:
            options_button.icon = self.icons["down_default"]
        options_button.iconSize = QSize(iw, ih)
        options_button.rect = orect
        options_button.features = QStyleOptionButton.Flat
        # Paint a Push Button Control.
        QApplication.style().drawControl(QStyle.CE_PushButton, options_button, painter)
         
        # Paint the description/status?
        painter.save()
        if stream.status == 0: #offline
            painter.setPen(Qt.darkGray)
            painter.drawText(r.left()+40, r.top()+8, r.width(), r.height(), Qt.AlignVCenter | Qt.AlignLeft, "Offline")
        else:
            painter.setPen(Qt.darkGreen)
            painter.drawText(r.left()+40, r.top()+8, r.width(), r.height(), Qt.AlignVCenter | Qt.AlignLeft, stream.channel.status)
        painter.restore()
Exemplo n.º 27
0
    def paint(self, painter, option, index):
        # NODE_REFERENCE ---------------------------------------------------
        if index.column() == NODE_REFERENCE:

            # backup painter
            painter.save()

            # paint background
            palette = QApplication.palette()
            if option.state & QStyle.State_Selected:
                bg_color = palette.highlight().color()
            else:
                bg_color = Qt.transparent
            painter.fillRect(option.rect, bg_color)

            # paint
            value = float(index.model().data(index))
            if value == 0.0:
                painter.setPen(
                    Qt.black
                    if option.state & QStyle.State_Selected
                    else Qt.darkGray
                )
                painter.setBrush(Qt.NoBrush)
                mid_size = 3.0
            else:
                painter.setPen(Qt.darkCyan)
                painter.setBrush(Qt.cyan)
                mid_size = 4.0

            h_center = round(option.rect.x() + (option.rect.width() * .5))
            v_center = round(option.rect.y() + (option.rect.height() * .5))
            losange = QPolygonF()
            losange.append(QPointF(h_center, v_center - mid_size))
            losange.append(QPointF(h_center - mid_size, v_center))
            losange.append(QPointF(h_center, v_center + mid_size))
            losange.append(QPointF(h_center + mid_size, v_center))

            painter.drawPolygon(losange)

            # restore painter
            painter.restore()

        # FILE_STATE -------------------------------------------------------
        elif index.column() == FILE_STATE:

            # backup painter
            painter.save()

            # paint background
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            painter.fillRect(option.rect, bg_color)

            # paint circle
            value = index.model().data(index)

            pen_color = [
                Qt.darkRed,
                Qt.black if option.state & QStyle.State_Selected else Qt.gray,
                Qt.darkGreen][value + 1]
            brush_color = [Qt.red, Qt.NoBrush, Qt.green][value + 1]

            painter.setPen(pen_color)
            painter.setBrush(brush_color)

            h_center = round(option.rect.x() + (option.rect.width() * .5))
            v_center = round(option.rect.y() + (option.rect.height() * .5))
            center = QPointF(h_center, v_center)

            painter.drawEllipse(center, 3.0, 3.0)

            # restore painter
            painter.restore()

        # NODE_NAME --------------------------------------------------------
        elif index.column() == NODE_NAME:
            text = index.model().data(index, Qt.DisplayRole)
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            txt_color = palette.highlightedText().color() \
                if option.state & QStyle.State_Selected \
                else palette.text().color()

            if MTTSettings.value('vizWrongNameState') \
                    and not MTTSettings.value('showWrongNameState'):
                file_name = os.path.splitext(os.path.basename(
                    index.model().data(
                        index.sibling(index.row(), NODE_FILE),
                        Qt.DisplayRole
                    )
                ))[0]
                if not re.split('[0-9]*$', text.rsplit(':')[-1])[0] == \
                        re.split('[0-9]*$', file_name)[0]:
                    bg_color = QBrush(
                        Qt.red
                        if option.state & QStyle.State_Selected
                        else Qt.darkRed,
                        Qt.Dense4Pattern
                    )

            if not MTTSettings.value('showNamespaceState'):
                splits = text.split(':')
                text = splits[len(splits) > 1]

            painter.save()
            painter.fillRect(option.rect, bg_color)
            painter.setPen(txt_color)
            rect = option.rect
            rect.setX(4)
            QApplication.style().drawItemText(
                painter, rect, Qt.AlignLeft | Qt.AlignVCenter,
                palette, True, text
            )
            painter.restore()

        # NODE_FILE ------------------------------------------------------------
        elif index.column() == NODE_FILE:
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            txt_color = palette.highlightedText().color() \
                if option.state & QStyle.State_Selected \
                else palette.text().color()

            text = index.model().data(index, Qt.DisplayRole)
            if MTTSettings.value('vizExternalState'):
                if not text.startswith(self.ws_path):
                    bg_color = QBrush(
                        '#ef7900'
                        if option.state & QStyle.State_Selected
                        else '#b05100',
                        Qt.Dense4Pattern)

            if MTTSettings.value('vizWrongPathState'):
                if not re.match(MTTSettings.PATH_PATTERN, text):
                    bg_color = QBrush(
                        Qt.red
                        if option.state & QStyle.State_Selected
                        else Qt.darkRed,
                        Qt.Dense4Pattern)

            if MTTSettings.value('showBasenameState'):
                text = os.path.basename(text)
            elif not MTTSettings.value('showRealAttributeValue'):
                if not text.startswith('\\'):
                    text = os.path.normpath(cmds.workspace(projectPath=text))

            painter.save()
            painter.fillRect(option.rect, bg_color)
            painter.setPen(txt_color)
            QApplication.style().drawItemText(
                painter, option.rect, Qt.AlignLeft | Qt.AlignVCenter,
                palette, True, text)
            painter.restore()
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
Exemplo n.º 28
0
        painter = QPainter()
        painter.begin(self)
        rect = QRect(5, 5, 100, self.parent.stupidSize)
        painter.drawRect(rect)
        painter.end()

class MainWindow(QMainWindow):
    
    def __init__(self, parent = None):
        super(MainWindow, self).__init__(parent)
        self.setWindowTitle('Button Size Test')
        self.stupidSize = 3
        self.dummyWidget = MyStupidWidget(self)
        #self.dummyWidget.addWidget(QPushButton('Knopka Huj'))
        self.setCentralWidget(self.dummyWidget)

    def sizeHint(self):
        return QSize(500, 400)

if __name__ == '__main__':
    myApp = QApplication(sys.argv)
    mainWindow = MainWindow()
    mainWindow.show()
    sizeFont = myApp.fontMetrics().height()
    sizeMargin = myApp.style().pixelMetric(QStyle.PM_ButtonMargin)
    print 'sizeFont: {0}, sizeMargin: {1}'.format(sizeFont, sizeMargin)
    mainWindow.stupidSize = sizeFont + sizeMargin
    mainWindow.dummyWidget.update()
    myApp.exec_()
    sys.exit(0)
Exemplo n.º 29
0
    def paint(self, painter, option, index):
        # NODE_REFERENCE ---------------------------------------------------
        if index.column() == NODE_REFERENCE:

            # backup painter
            painter.save()

            # paint background
            palette = QApplication.palette()
            if option.state & QStyle.State_Selected:
                bg_color = palette.highlight().color()
            else:
                bg_color = Qt.transparent
            painter.fillRect(option.rect, bg_color)

            # paint
            value = float(index.model().data(index))
            if value == 0.0:
                painter.setPen(Qt.black if option.state
                               & QStyle.State_Selected else Qt.darkGray)
                painter.setBrush(Qt.NoBrush)
                mid_size = 3.0
            else:
                painter.setPen(Qt.darkCyan)
                painter.setBrush(Qt.cyan)
                mid_size = 4.0

            h_center = round(option.rect.x() + (option.rect.width() * .5))
            v_center = round(option.rect.y() + (option.rect.height() * .5))
            losange = QPolygonF()
            losange.append(QPointF(h_center, v_center - mid_size))
            losange.append(QPointF(h_center - mid_size, v_center))
            losange.append(QPointF(h_center, v_center + mid_size))
            losange.append(QPointF(h_center + mid_size, v_center))

            painter.drawPolygon(losange)

            # restore painter
            painter.restore()

        # FILE_STATE -------------------------------------------------------
        elif index.column() == FILE_STATE:

            # backup painter
            painter.save()

            # paint background
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            painter.fillRect(option.rect, bg_color)

            # paint circle
            value = index.model().data(index)

            pen_color = [
                Qt.darkRed,
                Qt.black if option.state & QStyle.State_Selected else Qt.gray,
                Qt.darkGreen
            ][value + 1]
            brush_color = [Qt.red, Qt.NoBrush, Qt.green][value + 1]

            painter.setPen(pen_color)
            painter.setBrush(brush_color)

            h_center = round(option.rect.x() + (option.rect.width() * .5))
            v_center = round(option.rect.y() + (option.rect.height() * .5))
            center = QPointF(h_center, v_center)

            painter.drawEllipse(center, 3.0, 3.0)

            # restore painter
            painter.restore()

        # NODE_NAME --------------------------------------------------------
        elif index.column() == NODE_NAME:
            text = index.model().data(index, Qt.DisplayRole)
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            txt_color = palette.highlightedText().color() \
                if option.state & QStyle.State_Selected \
                else palette.text().color()

            if MTTSettings.value('vizWrongNameState') \
                    and not MTTSettings.value('showWrongNameState'):
                file_name = os.path.splitext(
                    os.path.basename(index.model().data(
                        index.sibling(index.row(), NODE_FILE),
                        Qt.DisplayRole)))[0]
                if not re.split('[0-9]*$', text.rsplit(':')[-1])[0] == \
                        re.split('[0-9]*$', file_name)[0]:
                    bg_color = QBrush(
                        Qt.red if option.state
                        & QStyle.State_Selected else Qt.darkRed,
                        Qt.Dense4Pattern)

            if not MTTSettings.value('showNamespaceState'):
                splits = text.split(':')
                text = splits[len(splits) > 1]

            painter.save()
            painter.fillRect(option.rect, bg_color)
            painter.setPen(txt_color)
            rect = option.rect
            rect.setX(4)
            QApplication.style().drawItemText(painter, rect,
                                              Qt.AlignLeft | Qt.AlignVCenter,
                                              palette, True, text)
            painter.restore()

        # NODE_FILE ------------------------------------------------------------
        elif index.column() == NODE_FILE:
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            txt_color = palette.highlightedText().color() \
                if option.state & QStyle.State_Selected \
                else palette.text().color()

            text = index.model().data(index, Qt.DisplayRole)
            if MTTSettings.value('vizExternalState'):
                if not text.startswith(self.ws_path):
                    bg_color = QBrush(
                        '#ef7900' if option.state
                        & QStyle.State_Selected else '#b05100',
                        Qt.Dense4Pattern)

            if MTTSettings.value('vizWrongPathState'):
                if not re.match(MTTSettings.PATH_PATTERN, text):
                    bg_color = QBrush(
                        Qt.red if option.state
                        & QStyle.State_Selected else Qt.darkRed,
                        Qt.Dense4Pattern)

            if MTTSettings.value('showBasenameState'):
                text = os.path.basename(text)
            elif not MTTSettings.value('showRealAttributeValue'):
                if not text.startswith('\\'):
                    text = os.path.normpath(cmds.workspace(projectPath=text))

            painter.save()
            painter.fillRect(option.rect, bg_color)
            painter.setPen(txt_color)
            QApplication.style().drawItemText(painter, option.rect,
                                              Qt.AlignLeft | Qt.AlignVCenter,
                                              palette, True, text)
            painter.restore()
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
Exemplo n.º 30
0
 def paintEvent(self, e):
     p = QPainter(self)
     style = QApplication.style()
     option = QStyleOptionButton()
     style.drawControl(QStyle.CE_PushButton, option, p)
     self._painted = True
Exemplo n.º 31
0
 def paintEvent(self, e):
     p = QPainter(self)
     style = QApplication.style()
     option = QStyleOptionButton()
     style.drawControl(QStyle.CE_PushButton, option, p)
     self._painted = True