本文整理汇总了Python中PyQt5.QtCore.QVariant方法的典型用法代码示例。如果您正苦于以下问题:Python QtCore.QVariant方法的具体用法?Python QtCore.QVariant怎么用?Python QtCore.QVariant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore
的用法示例。
在下文中一共展示了QtCore.QVariant方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setData
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QVariant [as 别名]
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
示例2: displayText
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QVariant [as 别名]
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 ""
示例3: data
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QVariant [as 别名]
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()
示例4: closeEvent
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QVariant [as 别名]
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()
示例5: aboutToShow_MenuRecentFiles
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QVariant [as 别名]
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
示例6: data
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QVariant [as 别名]
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))
示例7: data
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QVariant [as 别名]
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
示例8: completerModel
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QVariant [as 别名]
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)))
]
)
示例9: compare
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QVariant [as 别名]
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)
示例10: setScale
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QVariant [as 别名]
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()}}};"
)
示例11: setColor
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QVariant [as 别名]
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()}}};"
)
示例12: data
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QVariant [as 别名]
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()
示例13: data
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QVariant [as 别名]
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()
示例14: data
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QVariant [as 别名]
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()
示例15: data
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QVariant [as 别名]
def data(self, index, role=QtCore.Qt.DisplayRole):
if index.isValid():
if(role==QtCore.Qt.DisplayRole):
return self._data.values[index.row()][index.column()]
else:
# self._roleName 은 QHash(int, QByteArray)
columnName = self._roleNames[role].data().decode('utf8')
print('row {} col {} role {} columnName {} '.format(index.row(), index.column(), role, columnName))
print(self._data.at[index.row(), columnName])
return self._data.at[index.row(), columnName]
return QVariant()