本文整理汇总了Python中PyQt5.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):
if date_read == UNDEFINED_DATE and default_to_today:
date_read = now()
if is_read_only:
QTableWidgetItem.__init__(self, format_date(date_read, None), QtGui.QTableWidgetItem.UserType)
self.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled)
else:
QTableWidgetItem.__init__(self, '', QtGui.QTableWidgetItem.UserType)
self.setData(Qt.DisplayRole, QDateTime(date_read))
示例3: fill_in_table
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:
item.setData(Qt.DisplayRole, tag)
self.table.setItem(row, 2, item)
self.table.blockSignals(False)
return select_item
示例4: __init__
def __init__(self, date_read, is_read_only=False, default_to_today=False, fmt=None):
# debug_print("DateTableWidgetItem:__init__ - date_read=", date_read)
if date_read is None or date_read == UNDEFINED_DATE and default_to_today:
date_read = now()
if is_read_only:
QTableWidgetItem.__init__(self, format_date(date_read, fmt), QTableWidgetItem.UserType)
self.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled)
self.setData(Qt.DisplayRole, QDateTime(date_read))
else:
QTableWidgetItem.__init__(self, '', QTableWidgetItem.UserType)
self.setData(Qt.DisplayRole, QDateTime(date_read))
示例5: addGroupe
def addGroupe (self,groupe_name,type_alert):
item_name =QTableWidgetItem(groupe_name)
item_type =QTableWidgetItem(type_alert)
if item_type == "delete":
item_name.setBackground(QBrush("red"))
item_type.setBackground(QBrush("red"))
elif item_type == "new":
item_name.setBackground(QBrush("green"))
item_type.setBackground(QBrush("green"))
self.list_modified_groupes.insertRow(0)
self.list_modified_groupes.setItem(0,0,item_name)
self.list_modified_groupes.setItem(0,1,item_type)
示例6: update_table
def update_table(self, init=False):
if init:
self.init_table()
records = DatabaseManager.get_all_keyboards()
self.keyboard_table.setRowCount(records[0])
for idx, record in enumerate(records[1]):
self.keyboard_table.setItem(idx, 1, QTableWidgetItem(record.language_name))
self.keyboard_table.setItem(idx, 2, QTableWidgetItem(str(record.id)))
chk_box = QTableWidgetItem()
chk_box.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
chk_box.setCheckState(Qt.Unchecked)
self.keyboard_table.setItem(idx, 0, chk_box)
self.keyboard_table.resizeRowsToContents()
return
示例7: __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)
try:
self.rh_label.setText(self.rh_label.text() % localize_user_manual_link(
'https://manual.calibre-ebook.com/regexp.html'))
except TypeError:
pass # link already localized
示例8: 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)
示例9: fill_in_table
def fill_in_table(self, tags, tag_to_match):
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'])
item.setText(self.all_tags[tag]['cur_name'])
item.set_initial_text(tag)
item.setData(Qt.UserRole, self.all_tags[tag]['key'])
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 tag != self.all_tags[tag]['cur_name'] or self.all_tags[tag]['is_deleted']:
item.setData(Qt.DisplayRole, tag)
self.table.setItem(row, 2, item)
self.table.blockSignals(False)
return select_item
示例10: __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)
示例11: setData
def setData(self, role, data):
if role == Qt.EditRole:
self.previous_value = self.current_value
self.current_value = data
QTableWidgetItem.setData(self, role, data)
示例12: __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)
示例13: __init__
def __init__(self, txt):
QTableWidgetItem.__init__(self, txt)
self.initial_value = txt
self.current_value = txt
self.previous_value = txt
示例14: __init__
def __init__(self, number, is_read_only=False):
QTableWidgetItem.__init__(self, '', QTableWidgetItem.UserType)
self.setData(Qt.DisplayRole, number)
if is_read_only:
self.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled)
示例15: setup_row
def setup_row(self, field_metadata, row, col):
item = QTableWidgetItem(col)
self.opt_columns.setItem(row, 1, item)
if col.startswith('#'):
fm = self.custcols[col]
else:
fm = field_metadata[col]
if col == 'title':
coltype = _('Text')
elif col == 'ondevice':
coltype = _('Yes/No with text')
else:
dt = fm['datatype']
if fm['is_multiple']:
dt = '*' + dt
coltype = self.column_desc[dt]
item = QTableWidgetItem(coltype)
self.opt_columns.setItem(row, 2, item)
desc = fm['display'].get('description', "")
item = QTableWidgetItem(desc)
self.opt_columns.setItem(row, 3, item)
item = QTableWidgetItem(fm['name'])
item.setData(Qt.UserRole, (col))
self.opt_columns.setItem(row, 0, item)
if col.startswith('#'):
item.setData(Qt.DecorationRole, (QIcon(I('column.png'))))
flags = Qt.ItemIsEnabled|Qt.ItemIsSelectable
if col != 'ondevice':
flags |= Qt.ItemIsUserCheckable
item.setFlags(flags)
if col != 'ondevice':
item.setCheckState(Qt.Unchecked if col in self.hidden_cols else
Qt.Checked)