本文整理汇总了Python中PyQt4.Qt.QTableWidgetItem.setIcon方法的典型用法代码示例。如果您正苦于以下问题:Python QTableWidgetItem.setIcon方法的具体用法?Python QTableWidgetItem.setIcon怎么用?Python QTableWidgetItem.setIcon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QTableWidgetItem
的用法示例。
在下文中一共展示了QTableWidgetItem.setIcon方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TagListEditor
# 需要导入模块: from PyQt4.Qt import QTableWidgetItem [as 别名]
# 或者: from PyQt4.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)
# 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.setClickable(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)
self.table.setItem(row, 1, item)
item = QTableWidgetItem('')
item.setFlags (item.flags() & ~Qt.ItemIsSelectable)
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.accepted.connect(self.accepted)
self.search_box.initialize('tag_list_search_box_' + cat_name)
self.search_button.clicked.connect(self.search_clicked)
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 search_clicked(self):
#.........这里部分代码省略.........
示例2: EditAuthorsDialog
# 需要导入模块: from PyQt4.Qt import QTableWidgetItem [as 别名]
# 或者: from PyQt4.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.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 == id_to_select:
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)
l = QLabel(self.table)
self.not_found_label = l
l.setFrameStyle(QFrame.StyledPanel)
l.setAutoFillBackground(True)
#.........这里部分代码省略.........
示例3: insertItems
# 需要导入模块: from PyQt4.Qt import QTableWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTableWidgetItem import setIcon [as 别名]
def insertItems(self, row, items):
"""
Insert the <items> specified items in this list widget.
The list widget shows item name string , as a QListwidgetItem.
This QListWidgetItem object defines a 'key' of a dictionary
(self._itemDictionary) and the 'value' of this key is the object
specified by the 'item' itself.
Example: self._itemDictionary['C6'] = instance of class Atom.
@param row: The row number for the item.
@type row: int
@param items: A list of objects. These objects are treated as values in
the self._itemDictionary
@type items: list
@param setAsDefault: Not used here. See PM_ListWidget.insertItems where
it is used.
@see: self.renameItemValue() for a comment about
self._suppress_itemChanged_signal
"""
#self.__init__ for a comment about this flag
self._suppress_itemChanged_signal = True
#Clear the previous contents of the self._itemDictionary
self._itemDictionary.clear()
#Clear the contents of this list widget, using QListWidget.clear()
#See U{<http://doc.trolltech.com/4.2/qlistwidget.html>} for details
self.clear()
seq = ['Node name', 'Number of bases']
self.setHorizontalHeaderLabels(seq)
self.setRowCount(len(items))
idx = 0
self.setSortingEnabled(False)
for item in items:
if hasattr(item.__class__, 'name'):
itemName = item.name
else:
itemName = str(item)
numberOfBasesString = ''
if isinstance(item, self.win.assy.DnaStrand):
numberOfBasesString = str(len(item.getAllAtoms()))
elif isinstance(item, self.win.assy.DnaSegment):
numberOfBasesString = str(item.getNumberOfBasePairs())
tableWidgetItem = QTableWidgetItem(itemName)
###When we support editing list widget items , uncomment out the
###following line . See also self.editItems -- Ninad 2008-01-16
##tableWidgetItem.setFlags( tableWidgetItem.flags()| Qt.ItemIsEditable)
if hasattr(item.__class__, 'iconPath'):
try:
tableWidgetItem.setIcon(geticon(item.iconPath))
except:
print_compact_traceback()
self._itemDictionary[tableWidgetItem] = item
self.setItem(idx, 0, tableWidgetItem)
tableWidgetItem_column_2 = QTableWidgetItem(numberOfBasesString)
tableWidgetItem_column_2.setFlags(Qt.ItemIsEnabled)
self.setItem(idx, 1, tableWidgetItem_column_2)
idx += 1
#Reset the flag that temporarily suppresses itemChange signal.
self._suppress_itemChanged_signal = False
self.setSortingEnabled(True)