本文整理汇总了Python中PyQt5.Qt.QTableWidgetItem.setIcon方法的典型用法代码示例。如果您正苦于以下问题:Python QTableWidgetItem.setIcon方法的具体用法?Python QTableWidgetItem.setIcon怎么用?Python QTableWidgetItem.setIcon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QTableWidgetItem
的用法示例。
在下文中一共展示了QTableWidgetItem.setIcon方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TagListEditor
# 需要导入模块: from PyQt5.Qt import QTableWidgetItem [as 别名]
# 或者: from PyQt5.Qt.QTableWidgetItem import setIcon [as 别名]
class TagListEditor(QDialog, Ui_TagListEditor):
def __init__(self, window, cat_name, tag_to_match, data, sorter):
QDialog.__init__(self, window)
Ui_TagListEditor.__init__(self)
self.setupUi(self)
self.search_box.setMinimumContentsLength(25)
# Put the category name into the title bar
t = self.windowTitle()
self.setWindowTitle(t + ' (' + cat_name + ')')
# Remove help icon on title bar
icon = self.windowIcon()
self.setWindowFlags(self.windowFlags()&(~Qt.WindowContextHelpButtonHint))
self.setWindowIcon(icon)
# Get saved geometry info
try:
self.table_column_widths = \
gprefs.get('tag_list_editor_table_widths', None)
except:
pass
# initialization
self.to_rename = {}
self.to_delete = set([])
self.original_names = {}
self.all_tags = {}
self.counts = {}
for k,v,count in data:
self.all_tags[v] = k
self.counts[v] = count
self.original_names[k] = v
# Set up the column headings
self.down_arrow_icon = QIcon(I('arrow-down.png'))
self.up_arrow_icon = QIcon(I('arrow-up.png'))
self.blank_icon = QIcon(I('blank.png'))
self.table.setColumnCount(3)
self.name_col = QTableWidgetItem(_('Tag'))
self.table.setHorizontalHeaderItem(0, self.name_col)
self.name_col.setIcon(self.up_arrow_icon)
self.count_col = QTableWidgetItem(_('Count'))
self.table.setHorizontalHeaderItem(1, self.count_col)
self.count_col.setIcon(self.blank_icon)
self.was_col = QTableWidgetItem(_('Was'))
self.table.setHorizontalHeaderItem(2, self.was_col)
self.count_col.setIcon(self.blank_icon)
# Capture clicks on the horizontal header to sort the table columns
hh = self.table.horizontalHeader()
hh.setSectionsClickable(True)
hh.sectionClicked.connect(self.header_clicked)
hh.sectionResized.connect(self.table_column_resized)
self.name_order = 0
self.count_order = 1
self.was_order = 1
# Add the data
select_item = None
self.table.setRowCount(len(self.all_tags))
for row,tag in enumerate(sorted(self.all_tags.keys(), key=sorter)):
item = NameTableWidgetItem(tag)
item.setData(Qt.UserRole, self.all_tags[tag])
item.setFlags(item.flags() | Qt.ItemIsSelectable | Qt.ItemIsEditable)
self.table.setItem(row, 0, item)
if tag == tag_to_match:
select_item = item
item = CountTableWidgetItem(self.counts[tag])
# only the name column can be selected
item.setFlags(item.flags() & ~(Qt.ItemIsSelectable|Qt.ItemIsEditable))
self.table.setItem(row, 1, item)
item = QTableWidgetItem('')
item.setFlags(item.flags() & ~(Qt.ItemIsSelectable|Qt.ItemIsEditable))
self.table.setItem(row, 2, item)
# Scroll to the selected item if there is one
if select_item is not None:
self.table.setCurrentItem(select_item)
self.delete_button.clicked.connect(self.delete_tags)
self.rename_button.clicked.connect(self.rename_tag)
self.table.itemDoubleClicked.connect(self._rename_tag)
self.table.itemChanged.connect(self.finish_editing)
self.buttonBox.button(QDialogButtonBox.Ok).setText(_('&OK'))
self.buttonBox.button(QDialogButtonBox.Cancel).setText(_('&Cancel'))
self.buttonBox.accepted.connect(self.accepted)
self.search_box.initialize('tag_list_search_box_' + cat_name)
self.search_box.editTextChanged.connect(self.find_text_changed)
self.search_button.clicked.connect(self.search_clicked)
self.search_button.setDefault(True)
self.start_find_pos = -1
try:
geom = gprefs.get('tag_list_editor_dialog_geometry', None)
#.........这里部分代码省略.........
示例2: EditAuthorsDialog
# 需要导入模块: from PyQt5.Qt import QTableWidgetItem [as 别名]
# 或者: from PyQt5.Qt.QTableWidgetItem import setIcon [as 别名]
class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog):
def __init__(self, parent, db, id_to_select, select_sort, select_link):
QDialog.__init__(self, parent)
Ui_EditAuthorsDialog.__init__(self)
self.setupUi(self)
# Remove help icon on title bar
icon = self.windowIcon()
self.setWindowFlags(self.windowFlags()&(~Qt.WindowContextHelpButtonHint))
self.setWindowIcon(icon)
try:
self.table_column_widths = \
gprefs.get('manage_authors_table_widths', None)
geom = gprefs.get('manage_authors_dialog_geometry', bytearray(''))
self.restoreGeometry(QByteArray(geom))
except:
pass
self.buttonBox.button(QDialogButtonBox.Ok).setText(_('&OK'))
self.buttonBox.button(QDialogButtonBox.Cancel).setText(_('&Cancel'))
self.buttonBox.accepted.connect(self.accepted)
# Set up the column headings
self.table.setSelectionMode(QAbstractItemView.SingleSelection)
self.table.setColumnCount(3)
self.down_arrow_icon = QIcon(I('arrow-down.png'))
self.up_arrow_icon = QIcon(I('arrow-up.png'))
self.blank_icon = QIcon(I('blank.png'))
self.auth_col = QTableWidgetItem(_('Author'))
self.table.setHorizontalHeaderItem(0, self.auth_col)
self.auth_col.setIcon(self.blank_icon)
self.aus_col = QTableWidgetItem(_('Author sort'))
self.table.setHorizontalHeaderItem(1, self.aus_col)
self.aus_col.setIcon(self.up_arrow_icon)
self.aul_col = QTableWidgetItem(_('Link'))
self.table.setHorizontalHeaderItem(2, self.aul_col)
self.aus_col.setIcon(self.blank_icon)
# Add the data
self.authors = {}
auts = db.get_authors_with_ids()
self.table.setRowCount(len(auts))
select_item = None
for row, (id, author, sort, link) in enumerate(auts):
author = author.replace('|', ',')
self.authors[id] = (author, sort, link)
aut = tableItem(author)
aut.setData(Qt.UserRole, id)
sort = tableItem(sort)
link = tableItem(link)
self.table.setItem(row, 0, aut)
self.table.setItem(row, 1, sort)
self.table.setItem(row, 2, link)
if id_to_select in (id, author):
if select_sort:
select_item = sort
elif select_link:
select_item = link
else:
select_item = aut
self.table.resizeColumnsToContents()
if self.table.columnWidth(2) < 200:
self.table.setColumnWidth(2, 200)
# set up the cellChanged signal only after the table is filled
self.table.cellChanged.connect(self.cell_changed)
# set up sort buttons
self.sort_by_author.setCheckable(True)
self.sort_by_author.setChecked(False)
self.sort_by_author.clicked.connect(self.do_sort_by_author)
self.author_order = 1
self.table.sortByColumn(1, Qt.AscendingOrder)
self.sort_by_author_sort.clicked.connect(self.do_sort_by_author_sort)
self.sort_by_author_sort.setCheckable(True)
self.sort_by_author_sort.setChecked(True)
self.author_sort_order = 1
self.recalc_author_sort.clicked.connect(self.do_recalc_author_sort)
self.auth_sort_to_author.clicked.connect(self.do_auth_sort_to_author)
# Position on the desired item
if select_item is not None:
self.table.setCurrentItem(select_item)
self.table.editItem(select_item)
self.start_find_pos = select_item.row() * 2 + select_item.column()
else:
self.table.setCurrentCell(0, 0)
self.start_find_pos = -1
# set up the search box
self.find_box.initialize('manage_authors_search')
self.find_box.lineEdit().returnPressed.connect(self.do_find)
self.find_box.editTextChanged.connect(self.find_text_changed)
self.find_button.clicked.connect(self.do_find)
self.find_button.setDefault(True)
l = QLabel(self.table)
#.........这里部分代码省略.........
示例3: TagListEditor
# 需要导入模块: from PyQt5.Qt import QTableWidgetItem [as 别名]
# 或者: from PyQt5.Qt.QTableWidgetItem import setIcon [as 别名]
#.........这里部分代码省略.........
self.apply_vl_checkbox.clicked.connect(self.vl_box_changed)
self.table.setEditTriggers(QTableWidget.EditKeyPressed)
try:
geom = gprefs.get('tag_list_editor_dialog_geometry', None)
if geom is not None:
self.restoreGeometry(QByteArray(geom))
else:
self.resize(self.sizeHint()+QSize(150, 100))
except:
pass
def vl_box_changed(self):
self.fill_in_table(None, None)
def fill_in_table(self, tags, tag_to_match):
data = self.get_book_ids(self.apply_vl_checkbox.isChecked())
self.all_tags = {}
for k,v,count in data:
self.all_tags[v] = {'key': k, 'count': count, 'cur_name': v,
'is_deleted': k in self.to_delete}
self.original_names[k] = v
self.ordered_tags = sorted(self.all_tags.keys(), key=self.sorter)
if tags is None:
tags = self.ordered_tags
select_item = None
self.table.blockSignals(True)
self.table.clear()
self.table.setColumnCount(3)
self.name_col = QTableWidgetItem(_('Tag'))
self.table.setHorizontalHeaderItem(0, self.name_col)
self.name_col.setIcon(self.up_arrow_icon)
self.count_col = QTableWidgetItem(_('Count'))
self.table.setHorizontalHeaderItem(1, self.count_col)
self.count_col.setIcon(self.blank_icon)
self.was_col = QTableWidgetItem(_('Was'))
self.table.setHorizontalHeaderItem(2, self.was_col)
self.count_col.setIcon(self.blank_icon)
self.table.setRowCount(len(tags))
for row,tag in enumerate(tags):
item = NameTableWidgetItem()
item.set_is_deleted(self.all_tags[tag]['is_deleted'])
_id = self.all_tags[tag]['key']
item.setData(Qt.UserRole, _id)
item.set_initial_text(tag)
if _id in self.to_rename:
item.setText(self.to_rename[_id])
else:
item.setText(tag)
item.setFlags(item.flags() | Qt.ItemIsSelectable | Qt.ItemIsEditable)
self.table.setItem(row, 0, item)
if tag == tag_to_match:
select_item = item
item = CountTableWidgetItem(self.all_tags[tag]['count'])
# only the name column can be selected
item.setFlags(item.flags() & ~(Qt.ItemIsSelectable|Qt.ItemIsEditable))
self.table.setItem(row, 1, item)
item = QTableWidgetItem()
item.setFlags(item.flags() & ~(Qt.ItemIsSelectable|Qt.ItemIsEditable))
if _id in self.to_rename or _id in self.to_delete: