本文整理汇总了Python中PyQt5.QtCore.Qt.ToolTipRole方法的典型用法代码示例。如果您正苦于以下问题:Python Qt.ToolTipRole方法的具体用法?Python Qt.ToolTipRole怎么用?Python Qt.ToolTipRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.Qt
的用法示例。
在下文中一共展示了Qt.ToolTipRole方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initData
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import ToolTipRole [as 别名]
def initData(self):
# 初始化数据
datas = open("Data/data.json", "rb").read()
encoding = chardet.detect(datas) or {}
datas = datas.decode(encoding.get("encoding", "utf-8"))
datas = json.loads(datas)
# 开始解析数据
for data in datas:
item_code = data.get("item_code") # 编码
item_name = data.get("item_name") # 名字
item = QStandardItem(item_name)
item.setData(item_code, Qt.ToolTipRole)
if item_code.endswith("0000"): # 4个0结尾的是市级以上的
self.province_model.appendRow(item)
elif item_code.endswith("00"): # 2个0结尾的是市
self.city_model.appendRow(item)
else: # 市以下
self.county_model.appendRow(item)
示例2: data
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import ToolTipRole [as 别名]
def data(self, index: QModelIndex, role=None):
item = self.getItem(index)
if role == Qt.DisplayRole:
return item.data()
elif role == Qt.DecorationRole and item.is_group:
return QIcon.fromTheme("folder")
elif role == Qt.CheckStateRole:
return item.show
elif role == Qt.FontRole:
if item.is_group and self.rootItem.index_of(item) in self.controller.active_group_ids:
font = QFont()
font.setBold(True)
return font
elif item.protocol in self.controller.selected_protocols:
font = QFont()
font.setBold(True)
return font
elif role == Qt.ToolTipRole:
return item.data()
示例3: test_label_tooltip
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import ToolTipRole [as 别名]
def test_label_tooltip(self):
self.cfc.ui.cbProtoView.setCurrentIndex(0)
self.cfc.add_protocol_label(0, 16, 2, 0, edit_label_name=False)
model = self.cfc.label_value_model
model.setData(model.index(0, 0), "test", Qt.EditRole)
table_model = self.cfc.protocol_model
for i in range(0, 16):
self.assertEqual(table_model.data(table_model.index(2, i), Qt.ToolTipRole), "test", msg=str(i))
for i in range(17, 100):
self.assertEqual(table_model.data(table_model.index(2, i), Qt.ToolTipRole), "", msg=str(i))
self.cfc.add_protocol_label(20, 24, 2, 0, edit_label_name=False)
checksum_field_type = next(ft for ft in self.cfc.field_types if ft.function == FieldType.Function.CHECKSUM)
model.setData(model.index(1, 0), checksum_field_type.caption, Qt.EditRole)
for i in range(20, 24):
self.assertIn("Expected", table_model.data(table_model.index(2, i), Qt.ToolTipRole))
for i in range(0, 20):
self.assertNotIn("Expected", table_model.data(table_model.index(2, i), Qt.ToolTipRole))
示例4: data
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import ToolTipRole [as 别名]
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
示例5: data
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import ToolTipRole [as 别名]
def data(self, index, role=Qt.DisplayRole):
if role == Qt.DisplayRole:
return self.reddit_object_list[index.row()].name
elif role == Qt.ForegroundRole:
if not self.reddit_object_list[index.row()].enable_download:
return QColor(255, 0, 0, 255) # set name text to red if download is disabled
else:
return None
elif role == Qt.DecorationRole:
return None
elif role == Qt.ToolTipRole:
return self.set_tooltips(self.reddit_object_list[index.row()])
elif role == Qt.EditRole:
return self.reddit_object_list[index.row()].name
示例6: data
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import ToolTipRole [as 别名]
def data(self, index, role=Qt.DisplayRole):
row = index.row()
item = self._items[row]
if role == Qt.DisplayRole:
icon = '◎ '
if item.name == DEFAULT_COLL_SONGS:
icon = '♫ '
elif item.name == DEFAULT_COLL_ALBUMS:
icon = '◉ '
return icon + item.name
if role == Qt.ToolTipRole:
return item.fpath
return super().data(index, role)
示例7: data
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import ToolTipRole [as 别名]
def data(self, index, role=Qt.DisplayRole):
row = index.row()
provider_id = self._items[row]
provider = self._association[provider_id]
if role == Qt.DisplayRole:
return provider.symbol + ' ' + provider.text
if role == Qt.ToolTipRole:
return provider.desc
if role == Qt.UserRole:
return provider
return super().data(index, role)
示例8: onEntered
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import ToolTipRole [as 别名]
def onEntered(self, index):
index = self.fmodel.mapToSource(index)
text = index.data(Qt.ToolTipRole)
if text:
self.retButton.setText(text)
self.retButton.setIcon(self.dmodel.itemFromIndex(index).icon())
示例9: onDoubleClicked
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import ToolTipRole [as 别名]
def onDoubleClicked(self, index):
index = self.fmodel.mapToSource(index)
text = index.data(Qt.ToolTipRole)
if text:
QApplication.clipboard().setText(text)
self.statusBar.showMessage('已复制: %s' % text)
示例10: __init__
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import ToolTipRole [as 别名]
def __init__(self, *args, **kwargs):
super(SortFilterProxyModel, self).__init__(*args, **kwargs)
self.setFilterRole(Qt.ToolTipRole) # 根据Qt.ToolTipRole角色过滤
self._model = QStandardItemModel(self)
self.setSourceModel(self._model)
示例11: setFilter
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import ToolTipRole [as 别名]
def setFilter(self, _):
# 过滤
# self.sender()#发送者
# 获取上一个下拉框中的item_code
item_code = self.sender().currentData(Qt.ToolTipRole)
if not item_code:
return
if item_code.endswith("0000"): # 过滤市
self.setFilterRegExp(QRegExp(item_code[:-4] + "\d\d00"))
elif item_code.endswith("00"): # 过滤市以下
self.setFilterRegExp(QRegExp(item_code[:-2] + "\d\d"))
示例12: test_label_value_table
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import ToolTipRole [as 别名]
def test_label_value_table(self):
table = self.cfc.ui.tblLabelValues # type: LabelValueTableView
model = table.model()
self.assertEqual(model.rowCount(), 0)
self.cfc.add_protocol_label(45, 56, 0, 0, edit_label_name=False)
self.assertEqual(model.rowCount(), 1)
self.assertEqual(model.data(model.index(0, 2)), "Bit")
self.assertEqual(model.data(model.index(0, 4)), "000011001110")
model.setData(model.index(0, 2), 1, role=Qt.EditRole)
self.assertEqual(model.data(model.index(0, 2)), "Hex")
self.assertEqual(model.data(model.index(0, 4)), "0ce")
model.setData(model.index(0, 2), 2, role=Qt.EditRole)
self.assertEqual(model.data(model.index(0, 2)), "ASCII")
model.setData(model.index(0, 2), 3, role=Qt.EditRole)
self.assertEqual(model.data(model.index(0, 2)), "Decimal")
self.assertEqual(model.data(model.index(0, 4)), "206")
model.setData(model.index(0, 2), 4, role=Qt.EditRole)
self.assertEqual(model.data(model.index(0, 2)), "BCD")
self.assertEqual(model.data(model.index(0, 4)), "0??")
self.assertIn("display type", model.data(model.index(0, 2), Qt.ToolTipRole))
self.assertIn("bit order", model.data(model.index(0, 3), Qt.ToolTipRole))
lbl = self.cfc.proto_analyzer.default_message_type[0]
self.assertEqual(lbl.display_endianness, "big")
model.setData(model.index(0, 3), "MSB/LE", role=Qt.EditRole)
self.assertEqual(lbl.display_endianness, "little")
model.setData(model.index(0, 3), "LSB/BE", role=Qt.EditRole)
self.assertEqual(lbl.display_endianness, "big")
示例13: __init__
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import ToolTipRole [as 别名]
def __init__(self, statusBar, config, *args, **kwargs):
super(FontViewWidget, self).__init__(*args, **kwargs)
self.statusBar = statusBar
layout = QVBoxLayout(self)
self.retButton = QToolButton(self)
self.retButton.setIconSize(QSize(60, 60))
self.retButton.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
self.retButton.setMinimumSize(200, 100)
self.retButton.setMaximumSize(200, 100)
layout.addWidget(self.retButton)
# 过滤输入框
layout.addWidget(
QLineEdit(self, textChanged=self.doFilter, placeholderText='过滤...'))
# Material Font
self.listView = QListView(self)
self.listView.setMouseTracking(True)
self.listView.setViewMode(QListView.IconMode)
self.listView.setMovement(QListView.Static)
self.listView.setFlow(QListView.LeftToRight)
self.listView.setWrapping(True)
self.listView.setEditTriggers(QListView.NoEditTriggers)
self.listView.setResizeMode(QListView.Adjust)
self.listView.doubleClicked.connect(self.onDoubleClicked)
self.listView.entered.connect(self.onEntered)
self.dmodel = QStandardItemModel(self.listView)
self.fmodel = QSortFilterProxyModel(self.listView)
self.fmodel.setSourceModel(self.dmodel)
self.fmodel.setFilterRole(Qt.ToolTipRole)
self.listView.setModel(self.fmodel)
layout.addWidget(self.listView)
# 字体加载器
loader = config[0]
# 添加Item
fontMap = json.loads(open(config[1], 'rb').read().decode(
encoding='utf_8', errors='ignore'), encoding='utf_8')
for name, _ in fontMap.items():
item = QStandardItem(loader.icon(name), '')
item.setData(name, Qt.ToolTipRole)
item.setData(name, Qt.StatusTipRole)
item.setTextAlignment(Qt.AlignCenter)
item.setFlags(item.flags())
self.dmodel.appendRow(item)
示例14: data
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import ToolTipRole [as 别名]
def data(self, index: QModelIndex, role=Qt.DisplayRole):
if not index.isValid():
return None
i, j = index.row(), index.column()
try:
lbl = self.display_labels[i]
except IndexError:
return None
if isinstance(lbl, ChecksumLabel) and self.message is not None:
calculated_crc = lbl.calculate_checksum_for_message(self.message, use_decoded_bits=True)
else:
calculated_crc = None
if role == Qt.DisplayRole:
if j == 0:
return lbl.name
elif j == 1:
return lbl.color_index
elif j == 2:
return lbl.DISPLAY_FORMATS[lbl.display_format_index]
elif j == 3:
return lbl.display_order_str
elif j == 4:
return self.__display_data(lbl, calculated_crc)
elif role == Qt.CheckStateRole and j == 0:
return lbl.show
elif role == Qt.BackgroundColorRole:
if isinstance(lbl, ChecksumLabel) and j == 4 and self.message is not None:
start, end = self.message.get_label_range(lbl, 0, True)
if calculated_crc == self.message.decoded_bits[start:end]:
return settings.BG_COLOR_CORRECT
else:
return settings.BG_COLOR_WRONG
else:
return None
elif role == Qt.ToolTipRole:
if j == 2:
return self.tr("Choose display type for the value of the label:"
"<ul>"
"<li>Bit</li>"
"<li>Hexadecimal (Hex)</li>"
"<li>ASCII chars</li>"
"<li>Decimal Number</li>"
"<li>Binary Coded Decimal (BCD)</li>"
"</ul>")
if j == 3:
return self.tr("Choose bit order for the displayed value:"
"<ul>"
"<li>Most Significant Bit (MSB) [Default]</li>"
"<li>Least Significant Bit (LSB)</li>"
"<li>Least Significant Digit (LSD)</li>"
"</ul>")
elif role == Qt.FontRole and j == 0:
font = QFont()
font.setBold(i in self.selected_label_indices)
return font
示例15: data
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import ToolTipRole [as 别名]
def data(self, index: QModelIndex, role=Qt.DisplayRole):
if not index.isValid():
return None
i = index.row()
j = index.column()
if role == Qt.DisplayRole and self.display_data:
try:
alignment_offset = self.get_alignment_offset_at(i)
if j < alignment_offset:
return self.ALIGNMENT_CHAR
if self.proto_view == 0:
return self.display_data[i][j - alignment_offset]
elif self.proto_view == 1:
return "{0:x}".format(self.display_data[i][j - alignment_offset])
elif self.proto_view == 2:
return chr(self.display_data[i][j - alignment_offset])
except IndexError:
return None
elif role == Qt.TextAlignmentRole:
if i in self.first_messages:
return Qt.AlignHCenter + Qt.AlignBottom
else:
return Qt.AlignCenter
elif role == Qt.BackgroundColorRole:
return self.background_colors[i, j]
elif role == Qt.FontRole:
font = QFont()
font.setBold(self.bold_fonts[i, j])
font.setItalic(self.italic_fonts[i, j])
return font
elif role == Qt.TextColorRole:
return self.text_colors[i, j]
elif role == Qt.ToolTipRole:
return self.get_tooltip(i, j)
else:
return None