def __init__(self, parent: QTableView):
     QItemDelegate.__init__(self, parent)
     self.view = parent
     self.background_color = Qt.white
     p = self.view.palette()
     if p:
         self.background_color = p.color(QPalette.Active, p.Background)
Esempio n. 2
0
    def setEditorData(self, editor, index):  #pylint: disable=invalid-name
        """Populate the combo box.

        Set the current index of the combo box to be the current value in the model.
        """
        if not index.isValid():
            return

        if not isinstance(index.model(), QSqlRelationalTableModel):
            # If not a QSqlRelationalTableModel, must be a proxy model.
            proxy_model = index.model()
            self.setEditorData(editor, proxy_model.mapToSource(index))
            return

        sql_model = index.model()
        str_val = sql_model.data(index)

        combobox = None
        if isinstance(editor, QComboBox):
            combobox = editor

        if not str_val or not isinstance(str_val, str) or not combobox:
            QItemDelegate.setEditorData(self, editor, index)
            return

        combobox.setCurrentIndex(combobox.findText(str_val))
Esempio n. 3
0
    def createEditor(self, parent, option, index):  #pylint: disable=invalid-name
        """Return a combo box instance.

        The returned combo box instance should point to the proper relation model column.
        """
        if not index.isValid():
            return QItemDelegate.createEditor(self, parent, option, index)

        if not isinstance(index.model(), QSqlRelationalTableModel):
            # If not a QSqlRelationalTableModel, must be a proxy model.
            proxy_model = index.model()
            return self.createEditor(parent, option,
                                     proxy_model.mapToSource(index))

        sql_model = index.model()
        child_model = sql_model.relationModel(index.column())

        if not child_model:
            return QItemDelegate.createEditor(self, parent, option, index)

        column = child_model.fieldIndex(
            sql_model.relation(index.column()).displayColumn())

        combobox = QComboBox(parent)
        combobox.setModel(child_model)
        combobox.setModelColumn(column)
        combobox.installEventFilter(self)

        return combobox
Esempio n. 4
0
    def setModelData(self, editor, model, index):  #pylint: disable=invalid-name
        """Take the value in the combo box and write it to the model."""
        if not index.isValid():
            return

        if not isinstance(model, QSqlRelationalTableModel):
            proxy_model = model
            source_model = proxy_model.sourceModel()
            self.setModelData(editor, source_model,
                              proxy_model.mapToSource(index))
            return

        sql_model = model
        child_model = sql_model.relationModel(index.column())

        combobox = editor

        if not child_model or not combobox:
            QItemDelegate.setModelData(self, editor, model, index)
            return

        current_item = combobox.currentIndex()

        child_col_index = child_model.fieldIndex(
            sql_model.relation(index.column()).displayColumn())
        child_edit_index = child_model.fieldIndex(
            sql_model.relation(index.column()).indexColumn())

        child_col_data = child_model.data(
            child_model.index(current_item, child_col_index), Qt.DisplayRole)
        child_edit_data = child_model.data(
            child_model.index(current_item, child_edit_index), Qt.EditRole)

        sql_model.setData(index, child_col_data, Qt.DisplayRole)
        sql_model.setData(index, child_edit_data, Qt.EditRole)
Esempio n. 5
0
 def paint(self, painter, option, index):
     value = index.model().data(index, Qt.EditRole)
     try:
         number = float(value)        
         painter.drawText(option.rect, Qt.AlignCenter, "{:.{}f}".format(number, self.nDecimals))
     except :
         QItemDelegate.paint(self, painter, option, index)            
    def __init__(self, parent=None, *args):
        QItemDelegate.__init__(self, parent, *args)

        # pixmaps for curve icons
        self.curve_pixmaps = { openshot.BEZIER: QPixmap(os.path.join(info.IMAGES_PATH, "keyframe-%s.png" % openshot.BEZIER)),
                               openshot.LINEAR: QPixmap(os.path.join(info.IMAGES_PATH, "keyframe-%s.png" % openshot.LINEAR)),
                               openshot.CONSTANT: QPixmap(os.path.join(info.IMAGES_PATH, "keyframe-%s.png" % openshot.CONSTANT))
                             }
Esempio n. 7
0
 def paint(self, painter, option, index):
     value = index.data(QtCore.Qt.DisplayRole)
     style = QApplication.style()
     opt = QStyleOptionComboBox()
     opt.text = str(value)
     opt.rect = option.rect
     style.drawComplexControl(QStyle.CC_ComboBox, opt, painter)
     QItemDelegate.paint(self, painter, option, index)
    def __init__(self, parent=None, *args):
        QItemDelegate.__init__(self, parent, *args)

        # pixmaps for curve icons
        self.curve_pixmaps = {
            openshot.BEZIER: QPixmap(":/curves/keyframe-%s.png" % openshot.BEZIER),
            openshot.LINEAR: QPixmap(":/curves/keyframe-%s.png" % openshot.LINEAR),
            openshot.CONSTANT: QPixmap(":/curves/keyframe-%s.png" % openshot.CONSTANT),
            }
Esempio n. 9
0
    def __init__(self, parent):
        QItemDelegate.__init__(self, parent)

        checkboxRect = QRect(
            QApplication.style().subElementRect(
                QStyle.SE_CheckBoxIndicator, QStyleOptionButton(), None
            )
        )
        self.checkboxHalfWidth = int(checkboxRect.width() / 2)
Esempio n. 10
0
    def init_validator(self):
        modes = ['vent', 'foot', 'bil', 'defrost', 'defog', 'trl', 'hil']
        for i in modes:
            edit = self.RPM_tab.findChild(QLineEdit, i + '_edit')
            edit.setValidator(self.int_validator)
            edit.setMaxLength(4)

        value_delegate = QItemDelegate(self)
        value_delegate.createEditor = self.createEditor
        self.valve_table.setItemDelegateForColumn(1, value_delegate)
Esempio n. 11
0
    def setEditorData(self, editor, index):
        text = index.model().data(index, Qt.DisplayRole)
        if index.column() == QUALITY:
            i = editor.findText(text)
            if i == -1:
                i = 0
            editor.setCurrentIndex(i)

        else:
            QItemDelegate.setEditorData(self, editor, index)
Esempio n. 12
0
    def paint(self, painter, option, index):

        if index.column() != 0:
            QItemDelegate.paint(self, painter, option, index)
            return

        painter.fillRect(option.rect, option.palette.brush(QPalette.Base))
        painter.setPen(QPen(option.palette.color(QPalette.Text)))
        painter.drawText(option.rect.adjusted(4, 4, -4, -4),
                         Qt.TextShowMnemonic | Qt.AlignLeft | Qt.AlignVCenter,
                         str(index.data()))
Esempio n. 13
0
 def paint(self, painter, option, index):
     option.palette.setColor(
         QPalette.Highlight,
         QColor(index.data(Qt.BackgroundRole)).darker(107))
     option.palette.setColor(
         QPalette.HighlightedText,
         QColor(index.data(Qt.ForegroundRole)).darker(115))
     QItemDelegate.paint(self, painter, option, index)
     if option.showDecorationSelected and \
             (option.state & QStyle.State_Selected):
         painter.drawRect(option.rect)
Esempio n. 14
0
 def __init__(self,
              tblMat,
              materialCol,
              doseCol=-1,
              selected_detname=None,
              editable=False):
     QItemDelegate.__init__(self)
     self.tblMat = tblMat
     self.matCol = materialCol
     self.doseCol = doseCol
     self.editable = editable
     self.selected_detname = selected_detname
Esempio n. 15
0
    def setEditorData(self, editor, index):
        """Set Target Quality."""
        text = index.model().data(index, Qt.DisplayRole)
        if index.column() == COLUMNS.QUALITY:
            i = editor.findText(text)
            if i == -1:
                i = 0
            editor.setCurrentIndex(i)
        else:
            QItemDelegate.setEditorData(self, editor, index)

        self.parent.tb_tasks.setEditTriggers(QAbstractItemView.NoEditTriggers)
Esempio n. 16
0
 def setModelData(self, editor, model, idx):
     # NOT IMPLEMENTED----------------------------------------------
     if editor.objectName() in ['ftype', 'dtype', 'stype', 'fpath', 'UUID']:
         modeldata = idx.data(Qt.DisplayRole)
         dict_ = eval(modeldata)
         newvalue = editor.text()
         dict_[editor.objectName()] = newvalue
         model.setData(idx, str(dict_))
     elif editor.objectName() in ['timestamp']:
         return
     else:
         QItemDelegate.setModelData(self, editor, model, idx)
Esempio n. 17
0
 def __init__(self, parent, img_dir: str):
     QItemDelegate.__init__(self, parent, )
     self.img_dir = img_dir
     self.save_action = QAction('Save', self)
     self.set_icon(self.save_action, "*****@*****.**")
     self.save_action.triggered.connect(self.on_save_data)
     self.undo_action = QAction('Revert', self)
     self.set_icon(self.undo_action, "*****@*****.**")
     self.undo_action.triggered.connect(self.on_revert_data)
     self.editor = None
     self.old_data = ''
     self.cur_item_index = None
     self.data_history: Dict[QModelIndex, List[str]] = {}
Esempio n. 18
0
    def __init__(self, parent, width, height):
        QItemDelegate.__init__(self, parent)

        self.itemWidth = width
        self.itemHeight = height
        self.checkedIcon = None
        self.partiallyCheckedIcon = None
        self.uncheckedIcon = None
        self.pixmapUnckecked = QPixmap(self.itemWidth, self.itemHeight)
        self.drawPixmapForUnckecked()
        self.pixmapCkecked = QPixmap(self.itemWidth, self.itemHeight)
        self.drawPixmapForCkecked()
        self.pixmapPartiallyChecked = QPixmap(self.itemWidth, self.itemHeight)
        self.drawPixmapForPartiallyChecked()
        self.drawPixmapForDisabled()
Esempio n. 19
0
 def __init__(self, parent, width, height):
     QItemDelegate.__init__(self, parent)
     
     self.itemWidth = width
     self.itemHeight = height
     self.checkedIcon = None
     self.partiallyCheckedIcon = None
     self.uncheckedIcon = None
     self.pixmapUnckecked = QPixmap(self.itemWidth, self.itemHeight)
     self.drawPixmapForUnckecked()
     self.pixmapCkecked = QPixmap(self.itemWidth, self.itemHeight)
     self.drawPixmapForCkecked()
     self.pixmapPartiallyChecked = QPixmap(self.itemWidth, self.itemHeight)
     self.drawPixmapForPartiallyChecked()
     self.drawPixmapForDisabled()
Esempio n. 20
0
 def setModelData(self, editor, model, index):
     if isinstance(editor, QComboBox):
         model.setData(index, QVariant(editor.currentText()), Qt.EditRole)
     elif isinstance(editor, QTextEdit):
         model.setData(index, QVariant(editor.toPlainText()), Qt.EditRole)
     else:
         return QItemDelegate.setModelData(self, editor, model, index)
Esempio n. 21
0
 def createEditor(self, parent, option, index):
     delegate = self.delegates[index.column()]
     if delegate is not None:
         delegate.createEditor(parent, option,index)
     else:
         return QItemDelegate.createEditor(self, parent, option,index)
 #
 #
 # def commitAndCloseEditor(self):
 #     editor = self.sender()
 #     if isinstance(editor, (QTextEdit, QLineEdit)):
 #         self.emit(SIGNAL("commitData(QWidget*)"), editor)
 #         self.emit(SIGNAL("closeEditor(QWidget*)"), editor)
 #
 #
 # def setEditorData(self, editor, index):
 #     textClassify = index.model().data(index, Qt.DisplayRole).toString()
 #     if index.column() == TEU:
 #         value = textClassify.replace(QRegExp("[., ]"), "").toInt()[0]
 #         editor.setValue(value)
 #     elif index.column() in (OWNER, COUNTRY):
 #         i = editor.findText(textClassify)
 #         if i == -1:
 #             i = 0
 #         editor.setCurrentIndex(i)
 #     elif index.column() == NAME:
 #         editor.setText(textClassify)
 #     elif index.column() == DESCRIPTION:
 #         editor.setHtml(textClassify)
 #     else:
 #         QItemDelegate.setEditorData(self, editor, index)
 #
 #
 # def setModelData(self, editor, model, index):
 #     QItemDelegate.setModelData(self, editor, model, index)
 def editorEvent(self, event, model, option, index):
     if event.type() == QEvent.MouseButtonRelease and index.column(
     ) == 0 and index.flags() & Qt.ItemIsUserCheckable:
         toggled = Qt.Checked if model.data(
             index, Qt.CheckStateRole) == QVariant(
                 Qt.Unchecked) else Qt.Unchecked
         return model.setData(index, toggled, Qt.CheckStateRole)
     __event = QItemDelegate(self).editorEvent(event, model, option, index)
     animate_requested = False
     if event.type() == QEvent.MouseButtonRelease and self.animatable:
         if self.rowAnimator.row == index.row():
             epos = event.pos()
             if self.rowAnimator.hoverLinkFilter.link_rect.contains(
                     QPoint(epos.x(),
                            epos.y() + 32)):
                 url = QUrl(model.data(index, HomepageRole).toString())
                 QDesktopServices.openUrl(url)
                 return __event
             elif self.rowAnimator.hoverLinkFilter.button_rect.contains(
                     epos, True):
                 self.showPackageDetails(model, index)
                 return __event
         animate_requested = True
     elif event.type() == QEvent.KeyPress and self.animatable:
         # KeyCode 32 : Space key
         if event.key() == 32 and index.column(
         ) == index.model().columnCount() - 1:
             animate_requested = True
     if not unicode(model.data(
             index,
             DescriptionRole).toString()) == '' and animate_requested:
         self.rowAnimator.animate(index.row())
     return __event
Esempio n. 23
0
 def __init__(self,
              tblMat,
              materialCol,
              intensityCol=-1,
              unitsCol=2,
              selected_detname=None,
              editable=False,
              auto_s=False):
     QItemDelegate.__init__(self)
     self.tblMat = tblMat
     self.matCol = materialCol
     self.intensityCol = intensityCol
     self.unitsCol = unitsCol
     self.editable = editable
     self.selected_detname = selected_detname
     self.auto_s = auto_s
     self.settings = RaseSettings()
Esempio n. 24
0
 def createEditor(self, parent, option, index):
     if index.parent().isValid():
         # item has a parent -> no SimulationModule
         # TODO implement dropdown menu if property is a dict
         return QItemDelegate.createEditor(self, parent, option, index)
     else:
         # no parent -> top of hierarchy
         return self.comboDel.createEditor(parent, option, index)
 def createEditor(self, parent, option, index):
     if index.parent().isValid():
         # item has a parent -> no SimulationModule
         # TODO implement dropdown menu if property is a dict
         return QItemDelegate.createEditor(self, parent, option, index)
     else:
         # no parent -> top of hierarchy
         return self.comboDel.createEditor(parent, option, index)
Esempio n. 26
0
    def createEditor(self, parent, option, index):
        """Create a ComboBox to edit the Target Quality."""
        if index.column() == COLUMNS.QUALITY:
            editor = QComboBox(parent)
            self.parent.populate_quality_combo(combo=editor)
            editor.activated.connect(partial(self.update, editor, index))
            return editor

        return QItemDelegate.createEditor(self, parent, option, index)
Esempio n. 27
0
 def createEditor(self, parent, option, index):
     if index.column() == QUALITY:
         editor = QComboBox(parent)
         self.parent.populate_presets(cb_presets=editor)
         editor.activated.connect(partial(self.update,
                                          editor,
                                          index))
         return editor
     else:
         return QItemDelegate.createEditor(self, parent, option, index)
Esempio n. 28
0
 def updateEditorGeometry(self, editor, option, index):
     option.rect.setSize(editor.minimumSizeHint().expandedTo(
         option.rect.size()))
     if isinstance(editor, QComboBox):
         editor.setGeometry(option.rect)
     elif isinstance(editor, QTextEdit):
         editor.setMinimumWidth(480)
         editor.setMinimumHeight(160)
     else:
         return QItemDelegate.updateEditorGeometry(self, editor, option,
                                                   index)
Esempio n. 29
0
 def setEditorData(self, editor, index):
     if isinstance(editor, QComboBox):
         i = editor.findText(index.data(Qt.EditRole))
         if i > -1:
             editor.setCurrentIndex(i)
         else:
             editor.setEditText(index.data(Qt.EditRole))
         editor.lineEdit().selectAll()
     elif isinstance(editor, QTextEdit):
         editor.setText(str(index.data(Qt.EditRole)))
         editor.selectAll()
     else:
         return QItemDelegate.setEditorData(self, editor, index)
Esempio n. 30
0
 def eventFilter(self, editor, event):
     # check some key presses
     if event.type() == QEvent.KeyPress:
         # if we pressed return and aren't at the last column send a tab
         #            if event.key() == Qt.Key_Return and not self.lastcolumn:
         #                event.accept()
         #                event = QKeyEvent(QEvent.KeyPress, Qt.Key_Tab, Qt.NoModifier)
         # if we pressed tab and are in the last column send a return
         if event.key() == Qt.Key_Tab and self.lastcolumn:
             event.accept()
             event = QKeyEvent(QEvent.KeyPress, Qt.Key_Return,
                               Qt.NoModifier)
     # just pass the event up
     return QItemDelegate.eventFilter(self, editor, event)
Esempio n. 31
0
 def paint(self, painter, option, index):
     # Only run the standard delegate if flag is true.
     # else don't paint anything.
     flag = True
     # Only shade the deltas which are in col 0.
     if index.column() == 0:
         # Grab the delta value.
         delta = index.model().data(index, Qt.EditRole)
         if delta == ".":
             flag = True
         elif self.style == 2:
             # mark up - shade negative, or if goes past max mark
             if int(delta
                    ) < 0 or int(delta) + self.currentMark > self.maxMark:
                 flag = False
         elif self.style == 3:
             # mark down - shade positive, or if goes below 0
             if int(delta) > 0 or int(delta) + self.currentMark < 0:
                 flag = False
         elif self.style == 1:
             # mark-total - do not show deltas.
             flag = False
     if flag:
         QItemDelegate.paint(self, painter, option, index)
Esempio n. 32
0
 def paint(self, *args, **kwargs):
     column = args[2].column()
     value = args[2].data()
     if column == 2:
         progressBarOption = QStyleOptionProgressBar()
         progressBarOption.rect = args[1].rect
         progressBarOption.minimum = 0
         progressBarOption.maximum = 100
         if isinstance(value, int):
             progressBarOption.progress = int(value)
             progressBarOption.text = "{0}%".format(int(value))
         progressBarOption.textVisible = True
         QtWidgets.QApplication.style().drawControl(QStyle.CE_ProgressBar,
                                                    progressBarOption,
                                                    args[0], None)
         return
     return QItemDelegate.paint(self, *args, **kwargs)
    def sizeHint(self, option, index):
        sh = QItemDelegate.sizeHint(self, option, index)
        if index.isValid():
            data = index.data()
            h = 0
            offs = 0
            if isinstance(data, tuple) and len(data) > 0 and isinstance(
                    data[0], QPixmap):
                pix: QPixmap = data[0]
                h = pix.height()
                offs += 1

            fm = option.fontMetrics
            h1 = IconTextItemDelegate.CellVerticalMargin * 2 + IconTextItemDelegate.CellLinesMargin
            h1 += (fm.height() * 2) - 2
            h = max(h, h1)
            sh.setHeight(h)
        return sh
Esempio n. 34
0
    def editorEvent(self, event, model, option, index):
        #paket seçim olayında hata var seçim olayı gerçekleşiyor ama packageList sonraki seçimde görüyor
        #geçici çözümle giderildi tamamen çözülmeli
        if event.type() == QEvent.MouseButtonRelease and index.column(
        ) == 0 and index.flags() & Qt.ItemIsUserCheckable:
            toggled = Qt.Checked if model.data(
                index, Qt.CheckStateRole) == QVariant(
                    Qt.Unchecked) else Qt.Unchecked
            self.packageSelected.emit(bool(toggled))
            return model.setData(index, toggled, Qt.CheckStateRole)

        __event = QItemDelegate(self).editorEvent(event, model, option, index)

        animate_requested = False
        if event.type() == QEvent.MouseButtonRelease and self.animatable:
            if self.rowAnimator.row == index.row():
                epos = event.pos()
                if self.rowAnimator.hoverLinkFilter.link_rect.contains(
                        QPoint(epos.x(),
                               epos.y() + 32)):
                    url = QUrl(QVariant.value(model.data(index, HomepageRole)))
                    QDesktopServices.openUrl(url)
                    return __event
                elif self.rowAnimator.hoverLinkFilter.button_rect.contains(
                        epos, True):
                    self.showPackageDetails(model, index)
                    return __event
            animate_requested = True
        elif event.type() == QEvent.KeyPress and self.animatable:
            # KeyCode 32 : Space key
            if event.key() == 32 and index.column(
            ) == index.model().columnCount() - 1:
                animate_requested = True
        if not QVariant.value(model.data(
                index, DescriptionRole)) == '' and animate_requested:
            self.rowAnimator.animate(index.row())
        return __event
Esempio n. 35
0
 def __init__(self, parent, items, editable = False):
     self.items = items
     self.editable = editable
     QItemDelegate.__init__(self, parent)
Esempio n. 36
0
 def setEditorData(self, editor, index):
     if editor.text().strip():
         QItemDelegate.setEditorData(self, editor, index)
 def __init__(self, owner):
     QItemDelegate.__init__(self, owner)
Esempio n. 38
0
 def __init__(self, parent):
     # parent является обязательным аргументом для делегата
     # так как мы ссылаемся на него в методе paint (см ниже)
     #self.__c=Communicate()
     #self.clicked=self.__c.clicked
     QItemDelegate.__init__(self, parent)
 def __init__(self, parent=None):
     QItemDelegate.__init__(self, parent)
     self.comboDel = ComboDelegate()
 def __init__(self, parent=None):
     QItemDelegate.__init__(self, parent)
 def setModelData(self, editor, model, index):
     if isinstance(editor, QComboBox):
         self.comboDel.setModelData(editor, model, index)
     else:
         QItemDelegate.setModelData(self, editor, model, index)