本文整理汇总了Python中PyQt4.Qt.QTableWidgetItem类的典型用法代码示例。如果您正苦于以下问题:Python QTableWidgetItem类的具体用法?Python QTableWidgetItem怎么用?Python QTableWidgetItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTableWidgetItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, text, icon, tooltip=None, is_read_only=False):
QTableWidgetItem.__init__(self, text)
if icon:
self.setIcon(icon)
if tooltip:
self.setToolTip(tooltip)
if is_read_only:
self.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled)
示例2: __init__
def __init__(self, date_read, is_read_only=False, default_to_today=False, fmt=None):
if date_read == UNDEFINED_DATE and default_to_today:
date_read = now()
if is_read_only:
QTableWidgetItem.__init__(self, format_date(date_read, fmt), QtGui.QTableWidgetItem.UserType)
self.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled)
else:
QTableWidgetItem.__init__(self, '', QtGui.QTableWidgetItem.UserType)
self.setData(Qt.DisplayRole, QDateTime(date_read))
示例3: changeNew
def changeNew(self, index):
filter = self._filters[self._keys[int(index)]]
ct = self.app.preferences.ui.configTable
ct.clear()
n = 0
ct.setRowCount(len(filter.config))
for key, value in filter.config.items():
twi = QTableWidgetItem(key)
twi.setFlags(Qt.ItemIsSelectable)
ct.setItem(n, 0, twi)
ct.setItem(n, 1, QTableWidgetItem(value))
n += 1
示例4: _makeCheckItem
def _makeCheckItem(self, name, group, attr):
item = QTableWidgetItem(name)
if group is self.model.defgroup:
item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
item.setCheckState(Qt.Checked if getattr(group.style, attr) else Qt.Unchecked)
else:
item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsUserCheckable | Qt.ItemIsTristate)
item.setCheckState(self.ShowAttrToCheckState[getattr(group.style, attr)])
return item
示例5: data
def data(self, role):
if role == Qt.DisplayRole:
return self.current_value
elif role == Qt.EditRole:
return self.current_value
else:
return QTableWidgetItem.data(self, role)
示例6: __init__
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
# Dummy attributes to fool the Widget() option handler code. We handle
# everything in our *handler methods.
for i in range(1, 4):
x = 'sr%d_'%i
for y in ('search', 'replace'):
z = x + y
setattr(self, 'opt_'+z, z)
self.opt_search_replace = 'search_replace'
Widget.__init__(self, parent,
['search_replace',
'sr1_search', 'sr1_replace',
'sr2_search', 'sr2_replace',
'sr3_search', 'sr3_replace']
)
self.db, self.book_id = db, book_id
self.sr_search.set_msg(_('&Search Regular Expression'))
self.sr_search.set_book_id(book_id)
self.sr_search.set_db(db)
self.sr_search.doc_update.connect(self.update_doc)
proto = QTableWidgetItem()
proto.setFlags(Qt.ItemFlags(Qt.ItemIsSelectable + Qt.ItemIsEnabled))
self.search_replace.setItemPrototype(proto)
self.search_replace.setColumnCount(2)
self.search_replace.setColumnWidth(0, 320)
self.search_replace.setColumnWidth(1, 320)
self.search_replace.setHorizontalHeaderLabels([
_('Search Regular Expression'), _('Replacement Text')])
self.sr_add.clicked.connect(self.sr_add_clicked)
self.sr_change.clicked.connect(self.sr_change_clicked)
self.sr_remove.clicked.connect(self.sr_remove_clicked)
self.sr_load.clicked.connect(self.sr_load_clicked)
self.sr_save.clicked.connect(self.sr_save_clicked)
self.sr_up.clicked.connect(self.sr_up_clicked)
self.sr_down.clicked.connect(self.sr_down_clicked)
self.search_replace.currentCellChanged.connect(self.sr_currentCellChanged)
self.initialize_options(get_option, get_help, db, book_id)
示例7: on_type_cb_itemchanged
def on_type_cb_itemchanged(self):
''' changed index if new Setting hit create new Setting'''
for i in range(self.elem_tab.rowCount()):
try:
cb = self.type_idx_to_cb[i]
if(cb.currentText() == "new Setting ..."):
idx = cb.findText(self.type_item_state[i])
cb.setCurrentIndex(idx)
self.new_setting(i)
continue
if cb.currentText() != self.type_item_state[i] and cb.currentText() != 'CUSTOMIZED':
''' load values '''#
itm = self.elem_tab.item(i, 1)
txt = itm.text()
cor_dic = self.type_to_dict[txt]
try:
val = cor_dic[cb.currentText()]
self.elem_tab.setItem(i, 3, QTableWidgetItem(str(val)))
except:
pass
self.db_lookup_dict[txt]
itm1 = self.elem_tab.item(i, 0)
itm2 = self.elem_tab.item(i, 1)
''' if DB Lookup show request -> double click opens window: edit request and edit the condition '''
[request, spec] = TimingDBMap().lookup_from_spec(itm1.text(), itm2.text(), cb.currentText())
[condition, spec] = TimingDBMap().conditions_from_spec(itm1.text(), itm2.text(), cb.currentText())
itm = QTableWidgetItem(request)
self.elem_tab.setItem(i, 4, itm)
itm.setToolTip("Conditions: \n%s" % self._pretty_str_cond(condition))
self.db_lookup_idx_to_info[i] = [condition, request, spec]
self.type_item_state[i] = cb.currentText()
except:
pass
示例8: __init__
def __init__(self, parent, items):
QDialog.__init__(self, parent)
Ui_DeleteMatchingFromDeviceDialog.__init__(self)
self.setupUi(self)
self.explanation.setText('<p>'+_('All checked books will be '
'<b>permanently deleted</b> from your '
'device. Please verify the list.')+'</p>')
self.buttonBox.accepted.connect(self.accepted)
self.buttonBox.rejected.connect(self.rejected)
self.table.cellClicked.connect(self.cell_clicked)
self.table.setSelectionMode(QAbstractItemView.NoSelection)
self.table.setColumnCount(7)
self.table.setHorizontalHeaderLabels(
['', _('Location'), _('Title'), _('Author'),
_('Date'), _('Format'), _('Path')])
rows = 0
for card in items:
rows += len(items[card][1])
self.table.setRowCount(rows)
row = 0
for card in items:
(model,books) = items[card]
for (id,book) in books:
item = QTableWidgetItem()
item.setFlags(Qt.ItemIsUserCheckable|Qt.ItemIsEnabled)
item.setCheckState(Qt.Checked)
item.setData(Qt.UserRole, (model, id, book.path))
self.table.setItem(row, 0, item)
self.table.setItem(row, 1, tableItem(card))
self.table.setItem(row, 2, titleTableItem(book.title))
self.table.setItem(row, 3, authorTableItem(book))
self.table.setItem(row, 4, dateTableItem(book.datetime))
self.table.setItem(row, 5, centeredTableItem(book.path.rpartition('.')[2]))
self.table.setItem(row, 6, tableItem(book.path))
row += 1
self.table.setCurrentCell(0, 1)
self.table.resizeColumnsToContents()
self.table.setSortingEnabled(True)
self.table.sortByColumn(2, Qt.AscendingOrder)
self.table.setCurrentCell(0, 1)
示例9: __init__
def __init__(self, val, sort, idx=0):
self.sort = sort
self.sort_idx = idx
QTableWidgetItem.__init__(self, val)
self.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
示例10: __init__
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
示例11: TagListEditor
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):
#.........这里部分代码省略.........
示例12: _fillSequenceTable
def _fillSequenceTable(self):
"""
Fills in the sequence table.
"""
if not self.current_protein:
return
else:
currentProteinChunk = self.current_protein
self.editingItem = True
aa_list = currentProteinChunk.protein.get_amino_acids()
aa_list_len = len(aa_list)
self.sequenceTable.setRowCount(aa_list_len)
for index in range(aa_list_len):
# Selection checkbox column
item_widget = QTableWidgetItem("")
item_widget.setFont(self.labelfont)
item_widget.setCheckState(Qt.Checked)
item_widget.setTextAlignment(Qt.AlignLeft)
item_widget.setSizeHint(QSize(20,12))
item_widget.setFlags(Qt.ItemIsSelectable |
Qt.ItemIsEnabled |
Qt.ItemIsUserCheckable)
self.sequenceTable.setItem(index, 0, item_widget)
# Amino acid index column
item_widget = QTableWidgetItem(str(index+1))
item_widget.setFont(self.labelfont)
item_widget.setFlags(
Qt.ItemIsSelectable |
Qt.ItemIsEnabled)
item_widget.setTextAlignment(Qt.AlignCenter)
self.sequenceTable.setItem(index, 1, item_widget)
# Mutation descriptor name column
aa = self._get_aa_for_index(index)
item_widget = QTableWidgetItem(self._get_descriptor_name(aa))
item_widget.setFont(self.labelfont)
item_widget.setFlags(Qt.ItemIsSelectable |
Qt.ItemIsEnabled)
item_widget.setTextAlignment(Qt.AlignCenter)
self.sequenceTable.setItem(index, 2, item_widget)
# Backrub checkbox column
item_widget = QTableWidgetItem("")
item_widget.setFont(self.labelfont)
if aa.get_backrub_mode():
item_widget.setCheckState(Qt.Checked)
else:
item_widget.setCheckState(Qt.Unchecked)
item_widget.setTextAlignment(Qt.AlignLeft)
item_widget.setSizeHint(QSize(20,12))
item_widget.setFlags(Qt.ItemIsSelectable |
Qt.ItemIsEnabled |
Qt.ItemIsUserCheckable)
self.sequenceTable.setItem(index, 3, item_widget)
# Mutation descriptor column
aa_string = self._get_mutation_descriptor(aa)
item_widget = QTableWidgetItem(aa_string)
item_widget.setFont(self.descriptorfont)
self.sequenceTable.setItem(index, 4, item_widget)
self.sequenceTable.setRowHeight(index, 16)
self.editingItem = False
self.sequenceTable.resizeColumnsToContents()
self.sequenceTable.setColumnWidth(0, 35)
self.sequenceTable.setColumnWidth(2, 80)
self.sequenceTable.setColumnWidth(3, 35)
return
示例13: populate_tbl_helper
def populate_tbl_helper(hsgui, tbl, col_headers, col_editable, row_list, row2_data_tup ):
#tbl = main_skel.chip_TBL
hheader = tbl.horizontalHeader()
sort_col = hheader.sortIndicatorSection()
sort_ord = hheader.sortIndicatorOrder()
tbl.sortByColumn(0, Qt.AscendingOrder) # Basic Sorting
prevBlockSignals = tbl.blockSignals(True)
tbl.clear()
tbl.setColumnCount(len(col_headers))
tbl.setRowCount(len(row_list))
tbl.verticalHeader().hide()
tbl.setHorizontalHeaderLabels(col_headers)
tbl.setSelectionMode( QAbstractItemView.SingleSelection )
tbl.setSelectionBehavior( QAbstractItemView.SelectRows)
tbl.setSortingEnabled(False)
for row in iter(row_list):
data_tup = row2_data_tup[row]
for col, data in enumerate(data_tup):
item = QTableWidgetItem()
try:
int_data = int(data)
item.setData(Qt.DisplayRole, int_data)
except ValueError: # for strings
item.setText(str(data))
except TypeError: #for lists
item.setText(str(data))
item.setTextAlignment(Qt.AlignHCenter)
if col_editable[col]: item.setFlags(item.flags() | Qt.ItemIsEditable)
else: item.setFlags(item.flags() ^ Qt.ItemIsEditable)
tbl.setItem(row, col, item)
tbl.setSortingEnabled(True)
tbl.sortByColumn(sort_col,sort_ord) # Move back to old sorting
tbl.show()
tbl.blockSignals(prevBlockSignals)
示例14: insertItems
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)
示例15: residuals2
def residuals2(self):
self.AObs=self.posterioriValue*self.A*(self.A.T*self.P*self.A)**-1*self.A.T
self.cofactorM=self.A*(self.A.T*self.P*self.A)**-1*self.A.T
self.AResObs=self.posterioriValue*(self.P**-1 - self.A*(self.A.T*self.P*self.A)**-1*self.A.T)
# print (self.A.T*self.P*self.A)**-1
# print self.posterioriValue
# print self.posterioriValue*(self.A.T*self.P*self.A)**-1
self.cofactorAObs.clear()
self.cofactorZ.clear()
self.residA=OrderedDict()
self.residARe=OrderedDict()
# print self.cofactorM
count = 0
for i,j in self.obs.iteritems():
for k,l in j.iteritems():
count+=1
self.obsCount=count
self.cofactorAObs.setColumnCount(count)
self.cofactorAObs.setRowCount(count)
self.cofactorZ.setColumnCount(count)
self.cofactorZ.setRowCount(count)
for i in range (count):
for j in range (count):
temp=QTableWidgetItem()
temp.setText(str(self.cofactorM[i,j]))
self.cofactorAObs.setItem(i,j,temp)
for i in range (count):
for j in range (count):
temp=QTableWidgetItem()
temp.setText(str(self.AResObs[i,j]))
self.cofactorZ.setItem(i,j,temp)
i=0
for x,sta in self.obs.iteritems():
for tn,tar in sta.iteritems():
name=x
# name=x[0:-2]
if not self.residA.has_key(x+tn):
self.residA[x+tn]=[None]
if not self.residARe.has_key(x+tn):
self.residARe[x+tn]=[None]
self.residA[x+tn][0]=sqrt(self.AObs[i,i])
self.residARe[x+tn][0]=sqrt(self.AResObs[i,i])
i+=1
# print self.residA
# print self.residARe
for x,sta in self.obs.iteritems():
for tn,target in sta.iteritems():
name=x+tn
item1 = QTreeWidgetItem(self.stdDevAtree)
item2 = QTreeWidgetItem(self.stdDevObsTree)
if tn[-1]=="D":
item1.setText(0, "Direction from"+ x +"to :"+tn[0:-2])
item2.setText(0,"Direction from"+ x+"to :"+tn[0:-2])
elif tn[-1]=="d":
item1.setText(0, "Distance from"+ x+"to :"+tn[0:-2])
item2.setText(0,"Distance from"+ x+"to :"+tn[0:-2])
item1.setText(1, str(round(float(self.residA[name][0]),3)))
item2.setText(1, str(round(float(self.residARe[name][0]),3)))