Python PyQt5.QtCore 模块,QVariant() 实例源码

我们从Python开源项目中,提取了以下34个代码示例,用于说明如何使用PyQt5.QtCore.QVariant()

项目:KerbalPie    作者:Vivero    | 项目源码 | 文件源码
def update_flight_data(self, parameter, value):
        if parameter in KPFlightDataModel.flight_data_lookup:
            row = KPFlightDataModel.flight_data_lookup.index(parameter)
            col = 2

            model_index = self.createIndex(row, col)

            # handle special formatting
            if parameter == 'vessel_rotation':
                value = "({:.3f},{:.3f},{:.3f},{:.3f})".format(value[0], value[1], value[2], value[3])

            self.setData(model_index, QVariant(value), Qt.EditRole)


    # O V E R R I D E   M E T H O D S 
    #===========================================================================
项目:plexdesktop    作者:coryo    | 项目源码 | 文件源码
def data(self, index, role):
        if not index.isValid():
            return QtCore.QVariant()
        if role == QtCore.Qt.UserRole:
            return index.internalPointer().plex_item
        elif role == QtCore.Qt.DisplayRole:
            return index.internalPointer().data(index.column())
        elif role == QtCore.Qt.DecorationRole:
            item = index.internalPointer().plex_item
            if not hasattr(item, 'thumb'):
                return QtCore.QVariant()
            key = item.thumb
            if not key:
                return plexdesktop.delegates.placeholder_thumb_generator(
                    index.internalPointer().data(index.column()))
            img = QtGui.QPixmapCache.find(key)
            if img:
                return img
            self.thumb_queue.put((item, index.row()))
            return QtCore.QVariant()
        else:
            return QtCore.QVariant()
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def AddCustomGCodeRowLayer(self, custom_gcode, parent_item, push_row=None):
        icon = QIcon()
        icon.addPixmap(QPixmap(":/images/custom.png"))
        item_col_0 = QStandardItem(icon, "")  # will only display a checkbox + an icon that will never be disabled
        item_col_0.setData(QtCore.QVariant(custom_gcode), CUSTOM_GCODE_OBJECT)  # store a ref to the custom gcode in our treeView element
        item_col_1 = QStandardItem(custom_gcode.name)
        item_col_2 = QStandardItem(str(custom_gcode.nr))
        item_col_3 = QStandardItem()
        if push_row:
            parent_item.insertRow(push_row, [item_col_0, item_col_1, item_col_2, item_col_3])
        else:
            parent_item.appendRow([item_col_0, item_col_1, item_col_2, item_col_3])

        # Deal with the checkboxes (shape enabled or disabled / send shape to TSP optimizer)
        item_col_0.setCheckState(QtCore.Qt.Unchecked if custom_gcode.isDisabled() else QtCore.Qt.Checked)

        flags = QtCore.Qt.ItemIsDragEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled
        item_col_0.setFlags(flags | QtCore.Qt.ItemIsUserCheckable)
        item_col_1.setFlags(flags)
        item_col_2.setFlags(flags)
        item_col_3.setFlags(flags)
项目:pysport    作者:sportorg    | 项目源码 | 文件源码
def data(self, index, role=None):
        if role == Qt.DisplayRole:
            # start = time.time()
            # answer = str(index.row()) + ' ' + str(index.column())
            answer = ''
            try:
                # answer = self.get_participation_data(index.row())[index.column()]
                row = index.row()
                column = index.column()
                answer = self.cache[row][column]
            except Exception as e:
                logging.exception(str(e))

            # end = time.time()
            # logging.debug('Data() ' + str(index.row()) + ' ' + str(index.column()) + ': ' + str(end - start) + ' s')
            return QVariant(answer)

        return QVariant()
项目:sarasvati    作者:advaita-krishna-das    | 项目源码 | 文件源码
def __update(self, thought):
        if thought is None:
            return
        state, actions = self.__plex.activate(thought, True)
        self.changed.notify(state, actions)

        for cmd in actions:
            v = {"cmd": cmd.name, "key": cmd.thought.key}

            if cmd.name == "add":
                v["title"] = cmd.thought.title
                v["x"] = cmd.data["pos"][0]
                v["y"] = cmd.data["pos"][1]
            if cmd.name == "move":  # or cmd.name == "set_pos_to":
                v["x"] = cmd.data[0]
                v["y"] = cmd.data[1]
            self.__command.emit(QVariant(v))

        if thought:
            for links in thought.links.all:
                self.__command.emit({"cmd": "link", "from": thought.key, "to": links.key,
                                     "ft": thought.title, "tt": links.title})
项目:bubblesub    作者:rr-    | 项目源码 | 文件源码
def headerData(self, idx, orientation, role=QtCore.Qt.DisplayRole):
        if orientation == QtCore.Qt.Vertical:
            if role == QtCore.Qt.DisplayRole:
                return idx + 1
            elif role == QtCore.Qt.TextAlignmentRole:
                return QtCore.Qt.AlignRight

        elif orientation == QtCore.Qt.Horizontal:
            column_type = self.column_order[idx]
            if role == QtCore.Qt.DisplayRole:
                return _HEADERS[column_type]
            elif role == QtCore.Qt.TextAlignmentRole:
                if column_type in (SubsModelColumn.Text, SubsModelColumn.Note):
                    return QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter
                return QtCore.Qt.AlignCenter

        return QtCore.QVariant()
项目:KerbalPie    作者:Vivero    | 项目源码 | 文件源码
def data(self, index, role):
        if role == Qt.DisplayRole:
            row = index.row()
            col = index.column()

            if col == 0:
                return QVariant(self._mp_database.db[row].name)
            elif col == 1:
                return QVariant(self._mp_database.db[row].state)

        return QVariant()
项目:KerbalPie    作者:Vivero    | 项目源码 | 文件源码
def headerData(self, section, orientation, role):
        if role == Qt.DisplayRole:
            if orientation == Qt.Horizontal:
                return QVariant(self._mp_table_header[section])

        return QVariant()
项目:KerbalPie    作者:Vivero    | 项目源码 | 文件源码
def _set_program_state(self, program_num, state):
        if program_num < len(self._mp_database.db):
            row = program_num
            col = 1

            model_index = self.createIndex(row, col)

            self.setData(model_index, QVariant(state), Qt.EditRole)


    # S L O T S 
    #===========================================================================
项目:KerbalPie    作者:Vivero    | 项目源码 | 文件源码
def data(self, index, role):
        if role == Qt.DisplayRole:
            row = index.row()
            col = index.column()

            return QVariant(self._flight_data[row][col])

        return QVariant()
项目:plexdesktop    作者:coryo    | 项目源码 | 文件源码
def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole):
        if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
            return self.root_item.data(section)
        return QtCore.QVariant()
项目:plexdesktop    作者:coryo    | 项目源码 | 文件源码
def data(self, index, role=QtCore.Qt.DisplayRole):
        if self.container is None:
            return QtCore.QVariant()
        if role == QtCore.Qt.DisplayRole:
            try:
                return self.container.children[index.row()].title
            except (AttributeError, IndexError):
                return QtCore.QVariant()
        elif role == QtCore.Qt.UserRole:
            try:
                return self.container.children[index.row()]
            except IndexError:
                return QtCore.QVariant()
        elif role == QtCore.Qt.DecorationRole:
            row = index.row()
            item = self.container.children[row]
            if hasattr(item, 'thumb_queued'):
                return QtCore.QVariant()
            key = item.thumb
            if not key:
                return plexdesktop.delegates.placeholder_thumb_generator(item.title)
            img = QtGui.QPixmapCache.find(key)
            if img:
                return img
            self._queue_thumb(item, row)
            # QtGui.QPixmapCache.insert(key, QtGui.QPixmap())
            # self.thumb_queue.put((item, row))
            return QtCore.QVariant()
        else:
            return QtCore.QVariant()
项目:TrezorSymmetricFileEncryption    作者:8go    | 项目源码 | 文件源码
def __init__(self, deviceMap):
        """
        Create dialog and fill it with labels from deviceMap

        @param deviceMap: dict device string -> device label
        """
        QDialog.__init__(self)
        self.setupUi(self)

        for deviceStr, label in deviceMap.items():
            item = QListWidgetItem(label)
            item.setData(Qt.UserRole, QVariant(deviceStr))
            self.trezorList.addItem(item)
        self.trezorList.setCurrentRow(0)
项目:PINCE    作者:korcankaraokcu    | 项目源码 | 文件源码
def data(self, QModelIndex, int_role=None):
        if not QModelIndex.isValid():
            return QVariant()
        if int_role == Qt.BackgroundColorRole:
            if QModelIndex.row() * self.column_count + QModelIndex.column() in self.breakpoint_list:
                return QVariant(QColor(Qt.red))
        elif int_role != Qt.DisplayRole:
            return QVariant()
        if self.data_array is None:
            return QVariant()
        return QVariant(self.data_array[QModelIndex.row() * self.column_count + QModelIndex.column()])
项目:PINCE    作者:korcankaraokcu    | 项目源码 | 文件源码
def data(self, QModelIndex, int_role=None):
        if not QModelIndex.isValid():
            return QVariant()
        if int_role == Qt.BackgroundColorRole:
            if QModelIndex.row() * self.column_count + QModelIndex.column() in self.breakpoint_list:
                return QVariant(QColor(Qt.red))
        elif int_role != Qt.DisplayRole:
            return QVariant()
        if self.data_array is None:
            return QVariant()
        return QVariant(
            SysUtils.aob_to_str(self.data_array[QModelIndex.row() * self.column_count + QModelIndex.column()]))
项目:pyqt5    作者:yurisnm    | 项目源码 | 文件源码
def headerData(self, section, orientation, role=None):
        if role == Qt.DisplayRole:
            return QVariant()
        if orientation == Qt.Horizontal:
            if section%2==0:
                return "x"
            else:
                return "y"
        else:
            return "{}".format(section+1)
项目:pyqt5    作者:yurisnm    | 项目源码 | 文件源码
def data(self, index, role=None):
        if role == Qt.DisplayRole:
            return self.m_data[index.row()][index.column()]
        elif role == Qt.EditRole:
            return self.m_data[index.row()][index.column()]
        elif role == Qt.BackgroundRole:
            for color, rect in self.m_mapping.items():
                if rect.contains(index.column(), index.row()):
                    return QColor(color)
        return QVariant()
项目:pyqt5    作者:yurisnm    | 项目源码 | 文件源码
def headerData(self, section, orientation, role=None):
        print(orientation)
        if role == Qt.DisplayRole:
            return QVariant()
        if orientation == Qt.Horizontal:
            if section%2==0:
                return "x"
            else:
                return "y"
        else:
            return "{}".format(section+1)
项目:pyqt5    作者:yurisnm    | 项目源码 | 文件源码
def data(self, index, role=None):
        if role == Qt.DisplayRole:
            return self.m_data[index.row()][index.column()]
        elif role == Qt.EditRole:
            return self.m_data[index.row()][index.column()]
        elif role == Qt.BackgroundRole:
            for color, rect in self.m_mapping.items():
                if rect.contains(index.column(), index.row()):
                    return QColor(color)
        return QVariant()
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def data(self, index, role=Qt.DisplayRole):
        try:
            animal = self._animals[index.row()]
        except IndexError:
            return QVariant()

        if role == self.TypeRole:
            return animal.type()

        if role == self.SizeRole:
            return animal.size()

        return QVariant()
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def data(self, index, role=Qt.DisplayRole):
        try:
            animal = self._animals[index.row()]
        except IndexError:
            return QVariant()

        if role == self.TypeRole:
            return animal.type()

        if role == self.SizeRole:
            return animal.size()

        return QVariant()
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def highlight(self):
            hi_selection = QtWidgets.QTextEdit.ExtraSelection()

            hi_selection.format.setBackground(self.palette().alternateBase())
            hi_selection.format.setProperty(QtGui.QTextFormat.FullWidthSelection, 1) #QtCore.QVariant(True)
            hi_selection.cursor = self.textCursor()
            hi_selection.cursor.clearSelection()

            self.setExtraSelections([hi_selection])
项目:sarasvati    作者:advaita-krishna-das    | 项目源码 | 文件源码
def __init_panel(self, engine):
        window = engine.rootObjects()[0]
        container = window.findChild(QQuickItem, "panel")

        toolboxes = self.__api.plugins.find("toolbox")
        for toolbox in toolboxes:
            try:
                toolbox.activate()
                itm = toolbox.get(engine)
                QMetaObject.invokeMethod(container, "append", Qt.DirectConnection, Q_ARG(QVariant, itm))
            except Exception:
                logging.error("Unable to instantiate {} toolbox".format(toolbox.__class__.__name__))
                pass
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def data(self, QModelIndex, role=None):
        data = self.itemData(QModelIndex)
        if role == Qt.DisplayRole:
            if QModelIndex.column() == 1:  # ??? ??? ????? ?? ?? ??.
                return QVariant()
            return data[0]
        if role == Qt.DecorationRole:
            return QPixmap(data[0]).scaledToHeight(25)
        return QVariant()
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def data(self, QModelIndex, role=None):
        data = self.itemData(QModelIndex)
        if role == Qt.DisplayRole:
            return "%s" % (data[role])
        elif role in data and role == Qt.DecorationRole:
            return QPixmap(data[role]).scaledToHeight(25)
        elif role == Qt.UserRole:
            print(data[role])
        return QVariant()
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def data(self, QModelIndex, role=None):
        data = self.itemData(QModelIndex)
        if role == Qt.DisplayRole:
            return "%s" % (data[role])
        elif role == Qt.UserRole:
            print(data[role])
        return QVariant()
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def data(self, QModelIndex, role=None):
        """
        ??? ???? ???? ? View? Model.data? ??
        View? ??? role? ???? ???? ?? ??
        ???? role? ?? ??? ?? ?? QVariant? ??
        """
        item = self._data[QModelIndex.row()]

        if role == Qt.DisplayRole:  # ? ???
            return "%s" % item['name']
        elif role == Qt.EditRole:  # ? ???
            return "%s" % item['name']
        return QVariant()
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def data(self, QModelIndex, role=None):
        item = self._data[QModelIndex.row()]

        if role == Qt.DisplayRole:
            return "%s" % (item['name'])
        elif role == Qt.DecorationRole:
            return QColor(item['color'])
        elif role == Qt.BackgroundRole:
            return QBrush(Qt.Dense7Pattern)
        elif role == Qt.ToolTipRole:
            return "Tool Tip: %s" % (item['name'])
        return QVariant()
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def data(self, QModelIndex, role=None):
        # itemData? ????? ?? QModelIndex? ???? ????? ??? ?? ????.
        data = self.itemData(QModelIndex)

        if role == Qt.DisplayRole:
            ret = data[role]
        elif role in data and role == Qt.DecorationRole:
            ret = QPixmap(data[role]).scaledToHeight(25)
        else:
            ret = QVariant()
        return ret
项目:ClassifyHub    作者:Top-Ranger    | 项目源码 | 文件源码
def get_result_list(self):
        list = []
        for result in self._results:
            dev, repo = result[0].get_dev_repo()
            list += ['{}/{}'.format(dev, repo)]
        return QVariant(list)

    ##
    # \brief Gets the class of a repository.
    #
    # \param dev Developer as string.
    # \param repo Repository as string.
    # \return String containing computed class.
项目:ClassifyHub    作者:Top-Ranger    | 项目源码 | 文件源码
def get_classifier_names(self):
        return QVariant(self._classifier_names)

    ##
    # \brief returns the probability of a class for a given classifier.
    #
    # \param dev Developer as string.
    # \param repo Repository as string.
    # \param target_class Class as string.
    # \param classifier Classifier as string.
    # \return Probability of the class for the given classifier.
项目:Visualization    作者:nwrush    | 项目源码 | 文件源码
def data(self, index, role=None):
        if role == Qt.DisplayRole:
            return self._data[index.row()]
        return QtCore.QVariant()  # Return an invalid variant
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def data(self, index, role=Qt.DisplayRole):
        try:
            animal = self._animals[index.row()]
        except IndexError:
            return QVariant()

        if role == self.TypeRole:
            return animal.type()

        if role == self.SizeRole:
            return animal.size()

        return QVariant()
项目:bubblesub    作者:rr-    | 项目源码 | 文件源码
def data(self, index, role=QtCore.Qt.DisplayRole):
        if role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole:
            row_idx = index.row()
            column_idx = index.column()

            style = self._styles[row_idx]
            if column_idx == StylesModelColumn.Name:
                return style.name
            elif column_idx == StylesModelColumn.FontName:
                return style.font_name
            elif column_idx == StylesModelColumn.FontSize:
                return int(style.font_size)
            elif column_idx == StylesModelColumn.Bold:
                return style.bold
            elif column_idx == StylesModelColumn.Italic:
                return style.italic
            elif column_idx == StylesModelColumn.Underline:
                return style.underline
            elif column_idx == StylesModelColumn.StrikeOut:
                return style.strike_out
            elif column_idx == StylesModelColumn.PrimaryColor:
                return _serialize_color(style.primary_color)
            elif column_idx == StylesModelColumn.SecondaryColor:
                return _serialize_color(style.secondary_color)
            elif column_idx == StylesModelColumn.BackColor:
                return _serialize_color(style.back_color)
            elif column_idx == StylesModelColumn.OutlineColor:
                return _serialize_color(style.outline_color)
            elif column_idx == StylesModelColumn.ShadowWidth:
                return float(style.shadow)
            elif column_idx == StylesModelColumn.OutlineWidth:
                return float(style.outline)
            elif column_idx == StylesModelColumn.ScaleX:
                return float(style.scale_x)
            elif column_idx == StylesModelColumn.ScaleY:
                return float(style.scale_y)
            elif column_idx == StylesModelColumn.Angle:
                return float(style.angle)
            elif column_idx == StylesModelColumn.Spacing:
                return float(style.spacing)
            elif column_idx == StylesModelColumn.MarginLeft:
                return int(style.margin_left)
            elif column_idx == StylesModelColumn.MarginRight:
                return int(style.margin_right)
            elif column_idx == StylesModelColumn.MarginVertical:
                return int(style.margin_vertical)
            elif column_idx == StylesModelColumn.Alignment:
                return style.alignment
            assert False

        return QtCore.QVariant()