Python PyQt5.QtCore.Qt.DisplayRole() Examples

The following are 30 code examples of PyQt5.QtCore.Qt.DisplayRole(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PyQt5.QtCore.Qt , or try the search function .
Example #1
Source File: first.py    From FIRST-plugin-ida with GNU General Public License v2.0 7 votes vote down vote up
def headerData(self, section, orientation, role=Qt.DisplayRole):
                '''The data for the given role and section in the header with
                the specified orientation.

                Args:
                    section (:obj:`int`):
                    orientation (:obj:`Qt.Orientation`):
                    role (:obj:`Qt.DisplayRole`):

                Returns:
                    data
                '''
                if role != Qt.DisplayRole:
                    return None

                if (orientation == Qt.Horizontal) and (section < len(self.header)):
                    return self.header[section]

                return None 
Example #2
Source File: ListModel.py    From WeiboSuperSpider with Apache License 2.0 7 votes vote down vote up
def data(self, index, role):
        if index.isValid() or (0 <= index.row() < len(self.ListItemData)):
            if role == Qt.DisplayRole:
                return QVariant(self.ListItemData[index.row()]['name'])
            elif role == Qt.DecorationRole:
                return QVariant(QIcon(self.ListItemData[index.row()]['iconPath']))
            elif role == Qt.SizeHintRole:
                return QVariant(QSize(70,80))
            elif role == Qt.TextAlignmentRole:
                return QVariant(int(Qt.AlignHCenter|Qt.AlignVCenter))
            elif role == Qt.FontRole:
                font = QFont()
                font.setPixelSize(20)
                return QVariant(font)
        else:            
            return QVariant() 
Example #3
Source File: tree_view.py    From vorta with GNU General Public License v3.0 6 votes vote down vote up
def headerData(self, section, orientation, role):
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            return self.column_names[section]

        return None 
Example #4
Source File: ComboBoxDelegateQt.py    From KStock with GNU General Public License v3.0 6 votes vote down vote up
def createEditor(self, parent, option, index):
        '''
        Return QComboBox with list of choices (either values or their associated keys if they exist).
        '''
        try:
            editor = QComboBox(parent)
            value = index.model().data(index, Qt.DisplayRole)
            for i, choice in enumerate(self.choices):
                if (type(choice) is tuple) and (len(choice) == 2):
                    # choice is a (key, value) tuple.
                    key, val = choice
                    editor.addItem(str(key))  # key MUST be representable as a str.
                    if val == value:
                        editor.setCurrentIndex(i)
                else:
                    # choice is a value.
                    editor.addItem(str(choice))  # choice MUST be representable as a str.
                    if choice == value:
                        editor.setCurrentIndex(i)
            return editor
        except:
            return None 
Example #5
Source File: ObjList.py    From KStock with GNU General Public License v3.0 6 votes vote down vote up
def headerData(self, section, orientation, role = Qt.DisplayRole):
        if role != Qt.DisplayRole:
            return None
        if ((orientation == Qt.Horizontal) and self.isRowObjects) or ((orientation == Qt.Vertical) and not self.isRowObjects):
            # Display property headers.
            try:
                return self.properties[section]['header']  # Property header.
            except (IndexError, KeyError):
                return None
        else:
            # Display object indices (1-based).
            return (section + 1) if (0 <= section < len(self.objects)) else None 
Example #6
Source File: ObjList.py    From KStock with GNU General Public License v3.0 6 votes vote down vote up
def data(self, index, role = Qt.DisplayRole):
        if not index.isValid():
            return None
        obj = self.getObject(index)
        prop = self.getProperty(index)
        if role == Qt.BackgroundRole:
            return color(obj.D)
        if role == Qt.TextAlignmentRole:
            return Qt.AlignCenter
        if (obj is None) or (prop is None):
            return None
        try:
            if role in [Qt.DisplayRole, Qt.EditRole]:
                return getAttrRecursive(obj, prop['attr'])
        except:
            return None
        return None 
Example #7
Source File: main_gui.py    From IDAngr with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def headerData(self, col, orientation, role):
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            return self.headerdata[col]
        return None 
Example #8
Source File: pytablemodel.py    From ray-optics with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def data(self, index, role):
        root = self.get_root_object()
        if role == Qt.DisplayRole or role == Qt.EditRole:
            r = index.row()
            c = index.column()
            eval_str = ('root' + self.colEvalStr[c]).format(r)
            try:
                val = eval(eval_str)
                valStr = self.colFormats[c].format(val)
                return valStr
            except IndexError:
                return ''
            except TypeError:
                print('Data type error: ', eval_str, val)
                return ''
        else:
            return None 
Example #9
Source File: shell_table_editor.py    From mhw_armor_edit with The Unlicense 6 votes vote down vote up
def data(self, index, role):
        if not index.isValid():
            return None
        node = index.internalPointer()
        if role == Qt.DisplayRole:
            if index.column() == 0:
                return node.name
            elif index.column() == 1:
                return node.capacity
            elif index.column() == 2:
                return node.recoil
            elif index.column() == 3:
                return node.reload
        elif role == Qt.FontRole:
            if index.column() in (1, 2, 3):
                return self.column_font
        return None 
Example #10
Source File: wallet_data_models.py    From dash-masternode-tool with MIT License 6 votes vote down vote up
def data(self, index, role=None):
        if index.isValid():
            data = index.internalPointer()
            col = index.column()
            if data:
                if role in (Qt.DisplayRole, Qt.EditRole):
                    if col == 0:
                        # if isinstance(data, Bip44AccountType):
                        #     return data.get_account_name()
                        # else:
                        #     return f'/{data.address_index}: {data.address}'
                        return data
                    elif col == 1:
                        b = data.balance
                        if b:
                            b = b/1e8
                        return b
                    elif col == 2:
                        b = data.received
                        if b:
                            b = b/1e8
                        return b
        return QVariant() 
Example #11
Source File: predefined_label.py    From CNNArt with Apache License 2.0 6 votes vote down vote up
def editCell(self,r,c):
        if c==0:
            nameDialog = NameDialog(self.table.item(r,c))
            name = nameDialog.popUp()
            nameItem = QTableWidgetItem(name)
            self.table.setItem(r,0,nameItem)
            colorItem = QTableWidgetItem()
            colorItem.setData(Qt.DisplayRole, QColor('blue'))
            self.table.setItem(r,1,colorItem)
            if r < len(self.labelHist):
                self.labelHist[r]=name
            else:
                self.labelHist.append(name)
            with open('configGUI/predefined_classes.txt', 'w') as f:
                for item in self.labelHist:
                    f.write("%s\n" % item.text()) 
Example #12
Source File: labelTable.py    From CNNArt with Apache License 2.0 6 votes vote down vote up
def data(self, index, role):
        if not index.isValid():
            return None
        if (index.column() == 0):
            value = self.mylist[index.row()][index.column()].text()
        else:
            value = self.mylist[index.row()][index.column()]
        if role == QtCore.Qt.EditRole:
            return value
            itemSelected.emit()
        elif role == QtCore.Qt.DisplayRole:
            return value
            itemSelected.emit()
        elif role == QtCore.Qt.CheckStateRole:
            if index.column() == 0:
                # print(">>> data() row,col = %d, %d" % (index.row(), index.column()))
                if self.mylist[index.row()][index.column()].isChecked():
                    return QtCore.Qt.Checked
                else:
                    return QtCore.Qt.Unchecked 
Example #13
Source File: treemodel.py    From QMusic with GNU Lesser General Public License v2.1 6 votes vote down vote up
def data(self, index, role):
        """ Returns the tree item at the given index and role
        """
        if not index.isValid():
            return None

        col = index.column()
        tree_item = index.internalPointer()
        obj = tree_item.obj

        if role == Qt.DisplayRole:
            try:
                attr = self._attr_cols[col].data_fn(tree_item)
                # Replace carriage returns and line feeds with unicode glyphs 
                # so that all table rows fit on one line. 
                #return attr.replace('', unichr(0x240A)).replace('\r', unichr(0x240D))
                return (attr.replace('\r', unichr(0x21B5))
                        .replace('', unichr(0x21B5))
                        .replace('\r', unichr(0x21B5)))
            except StandardError, ex:
                #logger.exception(ex)
                return "**ERROR**: {}".format(ex) 
Example #14
Source File: treemodel.py    From QMusic with GNU Lesser General Public License v2.1 6 votes vote down vote up
def headerData(self, section, orientation, role):
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            return self._attr_cols[section].name
        else:
            return None 
Example #15
Source File: debugger.py    From CQ-editor with Apache License 2.0 6 votes vote down vote up
def headerData(self, section, orientation, role=Qt.DisplayRole):
        if role == Qt.DisplayRole and orientation == Qt.Horizontal:
            return self.HEADER[section]
        return QAbstractTableModel.headerData(self, section, orientation, role) 
Example #16
Source File: treemodel.py    From PFramer with GNU General Public License v3.0 6 votes vote down vote up
def data(self, index, role):
        """ Returns the tree item at the given index and role
        """
        if not index.isValid():
            return None

        col = index.column()
        tree_item = index.internalPointer()
        obj = tree_item.obj

        if role == Qt.DisplayRole:
            try:
                attr = self._attr_cols[col].data_fn(tree_item)
                # Replace carriage returns and line feeds with unicode glyphs 
                # so that all table rows fit on one line. 
                #return attr.replace('\n', unichr(0x240A)).replace('\r', unichr(0x240D))
                return (attr.replace('\r\n', unichr(0x21B5))
                            .replace('\n', unichr(0x21B5))
                            .replace('\r', unichr(0x21B5)))
            except StandardError, ex:
                #logger.exception(ex)
                return "**ERROR**: {}".format(ex) 
Example #17
Source File: qmodels.py    From linux-show-player with GNU General Public License v3.0 6 votes vote down vote up
def headerData(self, section, orientation, role=Qt.DisplayRole):
        if role == Qt.DisplayRole and orientation == Qt.Horizontal:
            if section < len(self.columns):
                return self.columns[section]
            else:
                return section + 1
        if role == Qt.SizeHintRole and orientation == Qt.Vertical:
            return 0 
Example #18
Source File: diff_result.py    From vorta with GNU General Public License v3.0 6 votes vote down vote up
def data(self, index, role):
        if not index.isValid():
            return None

        item = index.internalPointer()

        if role == Qt.ForegroundRole:
            if item.itemData[1] == 'removed':
                return QVariant(QColor(Qt.red))
            elif item.itemData[1] == 'added':
                return QVariant(QColor(Qt.green))
            elif item.itemData[1] == 'modified' or item.itemData[1].startswith('['):
                return QVariant(QColor(Qt.darkYellow))

        if role == Qt.DisplayRole:
            return item.data(index.column())
        else:
            return None 
Example #19
Source File: completionmodel.py    From qutebrowser with GNU General Public License v3.0 6 votes vote down vote up
def data(self, index, role=Qt.DisplayRole):
        """Return the item data for index.

        Override QAbstractItemModel::data.

        Args:
            index: The QModelIndex to get item flags for.

        Return: The item data, or None on an invalid index.
        """
        if role != Qt.DisplayRole:
            return None
        cat = self._cat_from_idx(index)
        if cat:
            # category header
            if index.column() == 0:
                return self._categories[index.row()].name
            return None
        # item
        cat = self._cat_from_idx(index.parent())
        if not cat:
            return None
        idx = cat.index(index.row(), index.column())
        return cat.data(idx) 
Example #20
Source File: weapon_editor.py    From mhw_armor_edit with The Unlicense 6 votes vote down vote up
def data(self, qindex:QModelIndex, role=None):
        if role == Qt.DisplayRole or role == Qt.EditRole:
            entry = self.entries[qindex.row()]
            attr = self.columns[qindex.column()]
            value = getattr(entry, attr)
            if attr in ("gmd_name_index", "gmd_description_index"):
                return get_t9n(self.model, "t9n", value)
            elif attr == "kire_id":
                kire_model = self.model.get_relation_data("kire")
                if kire_model is None:
                    return None
                else:
                    return kire_model.entries[value]
            return value
        elif role == Qt.UserRole:
            entry = self.entries[qindex.row()]
            return entry 
Example #21
Source File: RedditObjectItemDisplayModel.py    From DownloaderForReddit with GNU General Public License v3.0 5 votes vote down vote up
def data(self, index, role=None):
        if not index.isValid():
            return None
        if role == Qt.DisplayRole:
            index = index.row()
            if self.display_list == 'previous_downloads':
                return self.reddit_object.previous_downloads[index]
            elif self.display_list == 'saved_submissions':
                return self.reddit_object.saved_submissions[index].url  # TODO: show more info on click
            elif self.display_list == 'saved_content':
                item = self.content_display[index]
                return '%s:  %s' % (item[0], item[1])
            else:
                return None 
Example #22
Source File: FailedDownloadsDialogModels.py    From DownloaderForReddit with GNU General Public License v3.0 5 votes vote down vote up
def data(self, index, role=Qt.DisplayRole):
        if not index.isValid():
            return None
        elif role != Qt.DisplayRole and role != Qt.ToolTipRole:
            return None
        row = index.row()
        col = index.column()
        try:
            item = getattr(self.data_list[row], attrify(self.header_data[col]))
        except (AttributeError, TypeError):
            item = None
        return item 
Example #23
Source File: FailedDownloadsDialogModels.py    From DownloaderForReddit with GNU General Public License v3.0 5 votes vote down vote up
def headerData(self, col, orientation, role=None):
        if role == Qt.DisplayRole and orientation == Qt.Horizontal:
            return QVariant(self.header_data[col])
        return QVariant() 
Example #24
Source File: weapon_gun_editor.py    From mhw_armor_edit with The Unlicense 5 votes vote down vote up
def handle_weapon_tree_view_activated(self, qindex: QModelIndex):
        self.mapper.setCurrentModelIndex(qindex)
        entry = self.item_model.entries[qindex.row()]
        self.tabs_weapon_details.setTabText(
            0, self.item_model.data(qindex, Qt.DisplayRole))
        self.crafting_requirements_editor.set_current(entry.id)
        if self.is_bow_type:
            index = self.bottle_table_model.index(entry.special_ammo_type, 0)
            self.bottle_mapper.setCurrentModelIndex(index)
        else:
            index = self.shell_table_model.index(entry.shell_table_id, 0, QModelIndex())
            self.shell_table_view.setRootIndex(index)
            self.shell_table_view.expandAll() 
Example #25
Source File: weapon_gun_editor.py    From mhw_armor_edit with The Unlicense 5 votes vote down vote up
def data(self, qindex, role=None):
        if role == Qt.DisplayRole or role == Qt.EditRole:
            return super().data(qindex, role)
        elif role == Qt.UserRole:
            entry = self.entries[qindex.row()]
            return entry
        return None 
Example #26
Source File: crafting_editor.py    From mhw_armor_edit with The Unlicense 5 votes vote down vote up
def data(self, qindex: QModelIndex, role=None):
        if not qindex.isValid():
            return
        node = qindex.internalPointer()
        if isinstance(node, CraftingRequirementGroupNode):
            if role == Qt.DisplayRole:
                return str(node.ref[qindex.column()])
        else:
            if role == Qt.DisplayRole:
                if qindex.column() == 0:
                    attr = node.prefix + "_id"
                    return getattr(node.ref, attr)
                elif qindex.column() == 1:
                    attr = node.prefix + "_qty"
                    return getattr(node.ref, attr) 
Example #27
Source File: treemodel.py    From PFramer with GNU General Public License v3.0 5 votes vote down vote up
def headerData(self, section, orientation, role):
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            return self._attr_cols[section].name
        else:
            return None 
Example #28
Source File: AddRedditObjectListModel.py    From DownloaderForReddit with GNU General Public License v3.0 5 votes vote down vote up
def data(self, index, role=Qt.DisplayRole):
        if role == Qt.DisplayRole:
            return self.name_list[index.row()]
        elif role == Qt.DecorationRole:
            name = self.name_list[index.row()]
            if self.validation_dict[name] is None:
                return None
            if self.validation_dict[name]:
                return self.valid_img
            else:
                return self.non_valid_img 
Example #29
Source File: mpl_qtquick1.py    From matplotlib_qtquick_playground with MIT License 5 votes vote down vote up
def data(self, index, role=Qt.DisplayRole):
        if(index.row() < 0 or index.row() >= len(self._data_series)):
            return QVariant()
        
        series = self._data_series[index.row()]
        
        if role == self.SelectedRole:
            return series.selected()
        elif role == self.NameRole:
            return series.name()
        elif role == self.DataRole:
            return series.data()
        
        return QVariant() 
Example #30
Source File: UserFinderListModel.py    From DownloaderForReddit with GNU General Public License v3.0 5 votes vote down vote up
def data(self, index, role=Qt.DisplayRole):
        if role == Qt.DisplayRole:
            return self.user_list[index.row()].name
        elif role == Qt.DecorationRole:
            return None