Python PyQt5.QtCore.QVariant() Examples
The following are 30
code examples of PyQt5.QtCore.QVariant().
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
, or try the search function
.
Example #1
Source File: ListModel.py From WeiboSuperSpider with Apache License 2.0 | 7 votes |
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 #2
Source File: diff_result.py From vorta with GNU General Public License v3.0 | 6 votes |
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 #3
Source File: code_analyzer.py From VUT-FIT-IFJ-2017-toolkit with GNU General Public License v3.0 | 6 votes |
def completerModel(self) -> QVariant: return QVariant( [ dict( identifier='.IFJcode17', type=Expression.ExpressionTypes.Header ) ] if '.IFJcode17' not in self.code else [] + [ dict( identifier=match, type=Expression.ExpressionTypes.Types ) for match in sorted(("int", "bool", "float", "string")) ] + [ dict( identifier=func, type=Expression.ExpressionTypes.Instruction ) for func in INSTRUCTIONS ] + [ dict( identifier=match, type=Expression.ExpressionTypes.Variable ) for match in sorted(set(self.VARIABLE_RE.findall(self._code))) ] )
Example #4
Source File: ObjList.py From KStock with GNU General Public License v3.0 | 6 votes |
def setData(self, index, value, role = Qt.EditRole): if not index.isValid(): return False obj = self.getObject(index) prop = self.getProperty(index) if (obj is None) or (prop is None): return None try: action = prop.get('action', None) if action is not None: if action == "button": getAttrRecursive(obj, prop['attr'])() # Call obj.attr() return True elif action == "fileDialog": pass # File loading handled via @property.setter obj.attr below. Otherwise just sets the file name text. if role == Qt.EditRole: if type(value) == QVariant: value = value.toPyObject() if (QT_VERSION_STR[0] == '4') and (type(value) == QString): value = str(value) setAttrRecursive(obj, prop['attr'], value) return True except: return False return False
Example #5
Source File: ComboBoxDelegateQt.py From KStock with GNU General Public License v3.0 | 6 votes |
def displayText(self, value, locale): ''' Show str rep of current choice (or choice key if choice is a (key, value) tuple). ''' try: if type(value) == QVariant: value = value.toPyObject() # QVariant ==> object for choice in self.choices: if (type(choice) is tuple) and (len(choice) == 2): # choice is a (key, value) tuple. # Display the key, not the value. key, val = choice if val == value: return str(key) else: # choice is a value. # Display it's str rep. if choice == value: return str(choice) # If value is not in our list of choices, show str rep of value. return str(value) except: return ""
Example #6
Source File: wallet_data_models.py From dash-masternode-tool with MIT License | 6 votes |
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 #7
Source File: Widget.py From nanovna-saver with GNU General Public License v3.0 | 6 votes |
def setScale(self, scale): self.group_box.setMaximumWidth(int(340 * scale)) self.label['actualfreq'].setMinimumWidth(int(100 * scale)) self.label['actualfreq'].setMinimumWidth(int(100 * scale)) self.label['returnloss'].setMinimumWidth(int(80 * scale)) if self.coloredText: color_string = QtCore.QVariant(self.color) color_string.convert(QtCore.QVariant.String) self.group_box.setStyleSheet( f"QGroupBox {{ color: {color_string.value()}; " f"font-size: {self._size_str()}}};" ) else: self.group_box.setStyleSheet( f"QGroupBox {{ font-size: {self._size_str()}}};" )
Example #8
Source File: anchor_position_dialog.py From crazyflie-clients-python with GNU General Public License v2.0 | 6 votes |
def data(self, index, role=None): value = self._anchor_positions[index.row()][index.column()] if index.isValid(): if index.column() == 0: if role == Qt.CheckStateRole: return QVariant(value) elif index.column() == 1: if role == Qt.DisplayRole: return QVariant(value) else: if role == Qt.DisplayRole: return QVariant('%.2f' % (value)) elif role == Qt.EditRole: return QVariant(value) elif role == Qt.BackgroundRole: return self._get_background(index.row(), index.column()) return QVariant()
Example #9
Source File: diff_code_analyzer.py From VUT-FIT-IFJ-2017-toolkit with GNU General Public License v3.0 | 6 votes |
def compare(self, new_code: str) -> QVariant: diff_lines = [] hunk = [] diff = list(unified_diff(self._code.splitlines(True), new_code.splitlines(True)))[2::] temp_code_diff = list(unified_diff(self._temp_code.splitlines(True), new_code.splitlines(True)))[2::] for line in diff: hunk_info_match = re.match(r'@@ -\d+,?\d* \+\d+,?\d* @@', line) if hunk_info_match is not None: diff_lines.extend(self._get_modified_lines(hunk)) hunk = [] hunk.append(line) if hunk: diff_lines.extend(self._get_modified_lines(hunk)) added_lines, removed_lines = self._get_lines_diffs(new_code) if added_lines: self.addedLines.emit(QVariant(added_lines)) if removed_lines: self.removedLines.emit(QVariant(removed_lines)) return QVariant(diff_lines)
Example #10
Source File: DefinitionTreeModel.py From Uranium with GNU Lesser General Public License v3.0 | 6 votes |
def data(self, index, role): if not self._container: return QVariant() if not index.isValid(): return QVariant() if role not in self._role_names: return QVariant() role_name = self._role_names[role] definition = index.internalPointer() try: data = getattr(definition, role_name.decode()) except AttributeError: data = "" return QVariant(str(data))
Example #11
Source File: tabmodel_z6.py From python101 with MIT License | 6 votes |
def data(self, index, rola=Qt.DisplayRole): """ Wyświetlanie danych """ i = index.row() j = index.column() if rola == Qt.DisplayRole: return '{0}'.format(self.tabela[i][j]) elif rola == Qt.CheckStateRole and (j == 3 or j == 4): if self.tabela[i][j]: return Qt.Checked else: return Qt.Unchecked elif rola == Qt.EditRole and j == 1: return self.tabela[i][j] else: return QVariant()
Example #12
Source File: tabmodel_z5.py From python101 with MIT License | 6 votes |
def data(self, index, rola=Qt.DisplayRole): """ Wyświetlanie danych """ i = index.row() j = index.column() if rola == Qt.DisplayRole: return '{0}'.format(self.tabela[i][j]) elif rola == Qt.CheckStateRole and (j == 3 or j == 4): if self.tabela[i][j]: return Qt.Checked else: return Qt.Unchecked elif rola == Qt.EditRole and j == 1: return self.tabela[i][j] else: return QVariant()
Example #13
Source File: Widget.py From nanovna-saver with GNU General Public License v3.0 | 6 votes |
def setColor(self, color): if color.isValid(): self.color = color p = self.btnColorPicker.palette() p.setColor(QtGui.QPalette.ButtonText, self.color) self.btnColorPicker.setPalette(p) if self.coloredText: color_string = QtCore.QVariant(color) color_string.convert(QtCore.QVariant.String) self.group_box.setStyleSheet( f"QGroupBox {{ color: {color_string.value()}; " f"font-size: {self._size_str()}}};" ) else: self.group_box.setStyleSheet( f"QGroupBox {{ font-size: {self._size_str()}}};" )
Example #14
Source File: mainWindow.py From pychemqt with GNU General Public License v3.0 | 6 votes |
def closeEvent(self, event=None): if self.okToContinue(): for tab in range(self.centralwidget.count()): centralwidget = self.centralwidget.widget(tab) scene = centralwidget.subWindowList()[0].widget().scene() scene.clearSelection() settings = QtCore.QSettings() if self.filename: filename = QtCore.QVariant(self.filename) else: filename = QtCore.QVariant() settings.setValue("LastFile", filename) if self.recentFiles: recentFiles = QtCore.QVariant(self.recentFiles) else: recentFiles = QtCore.QVariant() settings.setValue("RecentFiles", recentFiles) settings.setValue("Geometry", QtCore.QVariant(self.saveGeometry())) settings.setValue("MainWindow/State", QtCore.QVariant(self.saveState())) self.close() else: event.ignore()
Example #15
Source File: mainWindow.py From pychemqt with GNU General Public License v3.0 | 6 votes |
def aboutToShow_MenuRecentFiles(self): self.menuRecentFiles.clear() recentFiles = [] for fname in self.recentFiles: if fname not in self.filename and QtCore.QFile.exists(fname): recentFiles.append(fname) if recentFiles: self.menuRecentFiles.addSeparator() for i, fname in enumerate(recentFiles): action = QtWidgets.QAction("&%d %s" % (i + 1, fname), self) action.setData(QtCore.QVariant(fname)) action.triggered.connect(self.loadFile) self.menuRecentFiles.addAction(action) self.menuRecentFiles.addSeparator() self.menuRecentFiles.addAction( QtGui.QIcon(IMAGE_PATH + "button/clear.png"), QtWidgets.QApplication.translate("pychemqt", "Clear"), self.clearRecentFiles) # File Manipulation
Example #16
Source File: tabmodel_z6.py From python101 with MIT License | 5 votes |
def headerData(self, sekcja, kierunek, rola=Qt.DisplayRole): """ Zwraca nagłówki kolumn """ if rola == Qt.DisplayRole and kierunek == Qt.Horizontal: return self.pola[sekcja] elif rola == Qt.DisplayRole and kierunek == Qt.Vertical: return sekcja + 1 else: return QVariant()
Example #17
Source File: reports.py From QualCoder with MIT License | 5 votes |
def put_image_into_textedit(self, img, counter, text_edit): """ Scale image, add resource to document, insert image. """ path = self.app.project_path + img['mediapath'] document = text_edit.document() image = QtGui.QImageReader(path).read() image = image.copy(img['x1'], img['y1'], img['width'], img['height']) # scale to max 300 wide or high. perhaps add option to change maximum limit? scaler = 1.0 scaler_w = 1.0 scaler_h = 1.0 if image.width() > 300: scaler_w = 300 / image.width() if image.height() > 300: scaler_h = 300 / image.height() if scaler_w < scaler_h: scaler = scaler_w else: scaler = scaler_h # need unique image names or the same image from the same path is reproduced imagename = self.app.project_path + '/images/' + str(counter) + '-' + img['mediapath'] url = QtCore.QUrl(imagename) document.addResource(QtGui.QTextDocument.ImageResource, url, QtCore.QVariant(image)) cursor = text_edit.textCursor() image_format = QtGui.QTextImageFormat() image_format.setWidth(image.width() * scaler) image_format.setHeight(image.height() * scaler) image_format.setName(url.toString()) cursor.insertImage(image_format) text_edit.insertHtml("<br />") self.html_links.append({'imagename': imagename, 'image': image, 'avname': None, 'av0': None, 'av1': None, 'avtext': None}) if img['memo'] != "": text_edit.insertPlainText(_("Memo: ") + img['memo'] + "\n")
Example #18
Source File: binance_order.py From Pythonic with GNU General Public License v3.0 | 5 votes |
def limitOrder(self): logging.debug('BinanceOrder::limitOrder() called') self.limit_input = QWidget() self.limit_layout = QVBoxLayout(self.limit_input) self.limit_time_in_force_txt = QLabel() self.limit_time_in_force_txt.setText(QC.translate('', 'Time in force:')) self.limit_time_in_force_input = QComboBox() self.limit_time_in_force_input.addItem(QC.translate('', 'Good til canceled'), QVariant('GTC')) self.limit_time_in_force_input.addItem(QC.translate('', 'Immediate or Cancel'), QVariant('IOC')) self.limit_time_in_force_input.addItem(QC.translate('', 'Fill or Kill'), QVariant('FOK')) self.limit_price_txt = QLabel() self.limit_price_txt.setText(QC.translate('', 'Limit price:')) self.limit_price_input = QLineEdit() self.limit_price_input.setValidator(QDoubleValidator(999999, -999999, 8)) self.limit_input_params = QLabel() self.limit_input_params.setText( '{\'price\' : 12.345, \'quantity\' : 0.005, \'type\' : \'GTC\'/\'IOC\'/\'FOK\'}') self.limit_layout.addWidget(self.limit_time_in_force_txt) self.limit_layout.addWidget(self.limit_time_in_force_input) self.limit_layout.addWidget(self.limit_price_txt) self.limit_layout.addWidget(self.limit_price_input) self.limit_layout.addWidget(self.limit_input_params) self.order_box.addWidget(self.limit_input)
Example #19
Source File: view_graph_original.py From QualCoder with MIT License | 5 votes |
def put_image_into_textedit(self, img, counter, text_edit): """ Scale image, add resource to document, insert image. A counter is important as each image slice needs a unique name, counter adds the uniqueness to the name. """ path = self.project_path + img['mediapath'] document = text_edit.document() image = QtGui.QImageReader(path).read() image = image.copy(img['x1'], img['y1'], img['width'], img['height']) # scale to max 300 wide or high. perhaps add option to change maximum limit? scaler = 1.0 scaler_w = 1.0 scaler_h = 1.0 if image.width() > 300: scaler_w = 300 / image.width() if image.height() > 300: scaler_h = 300 / image.height() if scaler_w < scaler_h: scaler = scaler_w else: scaler = scaler_h # need unique image names or the same image from the same path is reproduced imagename = self.project_path + '/images/' + str(counter) + '-' + img['mediapath'] url = QtCore.QUrl(imagename) document.addResource(QtGui.QTextDocument.ImageResource, url, QtCore.QVariant(image)) cursor = text_edit.textCursor() image_format = QtGui.QTextImageFormat() image_format.setWidth(image.width() * scaler) image_format.setHeight(image.height() * scaler) image_format.setName(url.toString()) cursor.insertImage(image_format) text_edit.insertHtml("<br />")
Example #20
Source File: select_file.py From QualCoder with MIT License | 5 votes |
def data(self, index, role): if role == QtCore.Qt.DisplayRole: # show just the name rowitem = self.list[index.row()] return QtCore.QVariant(rowitem['name']) elif role == QtCore.Qt.UserRole: # return the whole python object rowitem = self.list[index.row()] return rowitem return QtCore.QVariant()
Example #21
Source File: return.py From Pythonic with GNU General Public License v3.0 | 5 votes |
def edit(self): logging.debug('edit() called ExecBranch') self.branchEditLayout = QVBoxLayout() self.branchEdit = QWidget(self) self.branchEdit.setMinimumSize(500, 400) self.branchEdit.setWindowFlags(Qt.Window) self.branchEdit.setWindowModality(Qt.WindowModal) self.branchEdit.setWindowTitle('Edit Branch') self.selectCondition = QComboBox() self.selectCondition.addItem('Greater than (>) ...', QVariant('>')) self.selectCondition.addItem('Greater or equal than (>=) ...', QVariant('>=')) self.selectCondition.addItem('Less than (<) ...', QVariant('<')) self.selectCondition.addItem('Less or equal than (<=) ...', QVariant('<=')) self.selectCondition.addItem('equal to (==) ...', QVariant('==')) self.selectCondition.addItem('NOT equal to (!=) ...', QVariant('!=')) self.checkNegate = QCheckBox('Negate query (if NOT ... )') self.checkNegate.stateChanged.connect(self.negate_changed) self.if_text_1 = QLabel() self.if_text_1.setText('if INPUT is ...') self.branchEditLayout.addWidget(self.checkNegate) self.branchEditLayout.addWidget(self.if_text_1) self.branchEditLayout.addWidget(self.selectCondition) self.branchEditLayout.addStretch(1) self.branchEdit.setLayout(self.branchEditLayout) self.branchEdit.show()
Example #22
Source File: tabmodel_z4.py From python101 with MIT License | 5 votes |
def data(self, index, rola=Qt.DisplayRole): """ Wyświetlanie danych """ i = index.row() j = index.column() if rola == Qt.DisplayRole: return '{0}'.format(self.tabela[i][j]) else: return QVariant()
Example #23
Source File: tabmodel_z5.py From python101 with MIT License | 5 votes |
def headerData(self, sekcja, kierunek, rola=Qt.DisplayRole): """ Zwraca nagłówki kolumn """ if rola == Qt.DisplayRole and kierunek == Qt.Horizontal: return self.pola[sekcja] elif rola == Qt.DisplayRole and kierunek == Qt.Vertical: return sekcja + 1 else: return QVariant()
Example #24
Source File: reqlist.py From guppy-proxy with MIT License | 5 votes |
def headerData(self, section, orientation, role): if role == Qt.DisplayRole and orientation == Qt.Horizontal: hd = self.header_order[section] return self.table_headers[hd] return QVariant()
Example #25
Source File: macros.py From guppy-proxy with MIT License | 5 votes |
def data(self, index, role): if role == Qt.DisplayRole: return self.macros[index.row()][0] return QVariant()
Example #26
Source File: macros.py From guppy-proxy with MIT License | 5 votes |
def headerData(self, section, orientation, role): if role == Qt.DisplayRole and orientation == Qt.Horizontal: return self.headers[section] return QVariant()
Example #27
Source File: macros.py From guppy-proxy with MIT License | 5 votes |
def data(self, index, role): if role == Qt.DisplayRole: if index.column() == 1: rowdata = self.macros[index.row()] macro = rowdata[index.column()] return macro.fname if role == Qt.CheckStateRole: if index.column() == 0: if self.macros[index.row()][0]: return 2 return 0 return QVariant()
Example #28
Source File: macros.py From guppy-proxy with MIT License | 5 votes |
def headerData(self, section, orientation, role): if role == Qt.DisplayRole and orientation == Qt.Horizontal: return self.headers[section] return QVariant()
Example #29
Source File: models.py From CorpusTools with BSD 3-Clause "New" or "Revised" License | 5 votes |
def data(self, index, role=None): if not index.isValid(): return QVariant() if role == Qt.DisplayRole: return self._data[index.row()][index.column()] else: return QVariant()
Example #30
Source File: models.py From CorpusTools with BSD 3-Clause "New" or "Revised" License | 5 votes |
def filterAcceptsRow(self, row, parent = None): header = self.sourceModel().headerData(row, Qt.Vertical, Qt.DisplayRole) if header == QVariant(): return False if header in self.sourceModel().consRows: return True else: return False