本文整理汇总了Python中PySide.QtGui.QTableWidgetItem.setData方法的典型用法代码示例。如果您正苦于以下问题:Python QTableWidgetItem.setData方法的具体用法?Python QTableWidgetItem.setData怎么用?Python QTableWidgetItem.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QTableWidgetItem
的用法示例。
在下文中一共展示了QTableWidgetItem.setData方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: coloredTableWidgetItem
# 需要导入模块: from PySide.QtGui import QTableWidgetItem [as 别名]
# 或者: from PySide.QtGui.QTableWidgetItem import setData [as 别名]
def coloredTableWidgetItem(self, text, color, userData=None):
item = QTableWidgetItem(text)
item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
item.setForeground(color)
if userData:
item.setData(Qt.UserRole, userData)
return item
示例2: insert_row
# 需要导入模块: from PySide.QtGui import QTableWidgetItem [as 别名]
# 或者: from PySide.QtGui.QTableWidgetItem import setData [as 别名]
def insert_row(self, row, list_of_data):
self.insertRow(row)
for c, data_item in enumerate(list_of_data):
qtype = self.get_qtype(data_item)
newItem = QTableWidgetItem(type=qtype)
if type(data_item) == str:
newItem.setText(data_item)
else:
newItem.setData(QtCore.Qt.DisplayRole, data_item)
newItem.setFont(QFont("Helvetica", 12))
self.setItem(row, c, newItem)
示例3: __init__
# 需要导入模块: from PySide.QtGui import QTableWidgetItem [as 别名]
# 或者: from PySide.QtGui.QTableWidgetItem import setData [as 别名]
def __init__(self, data_list, header_rows=0, roundit=None, cmap=None, click_handler=None, resize_columns=True, stretch_last=False, header_text=None, row_height=0, sort_column=0, sort_order=QtCore.Qt.AscendingOrder):
self._data_list = data_list
self._nrows = len(self._data_list)
self._ncols = len(self._data_list[0])
QTableWidget.__init__(self, self._nrows, self._ncols)
self.setWordWrap(True) # I think it is already true by default
if header_rows > 0:
self.setHorizontalHeaderLabels(self._data_list[0])
self._data_list = self._data_list[1:]
self._nrows -= 1
for r in range(self._nrows):
for c in range(self._ncols):
data_item = self._data_list[r][c]
qtype = self.get_qtype(data_item)
if (roundit != None) and (qtype == QFLOAT): # @UndefinedVariable
data_item = round(data_item, roundit)
if (r < header_rows - 1):
data_item = "_" + str(data_item) # do this so the header rows are sorted to the top
# newItem = QTableWidgetItem(str(data_item))
newItem = QTableWidgetItem(type=qtype)
if type(data_item) == str:
newItem.setText(data_item)
else:
newItem.setData(QtCore.Qt.DisplayRole, data_item)
if r < header_rows - 1:
newItem.setFont(QFont("Helvetica", 12, QFont.Bold))
else:
newItem.setFont(QFont("Helvetica", 12))
if (cmap != None) and (type(data_item) == float) and (r >= header_rows):
the_color = cmap.rgb_color_from_val(data_item)
newBrush = QBrush()
newBrush.setColor(QColor(the_color[0], the_color[1], the_color[2]))
newBrush.setStyle(QtCore.Qt.SolidPattern)
newItem.setBackground(newBrush)
self.setItem(r, c, newItem)
if resize_columns:
self.resizeColumnsToContents()
self.resizeRowsToContents()
self.sortItems(0, order=QtCore.Qt.AscendingOrder)
self.setSortingEnabled(True)
if row_height != 0:
vh = self.verticalHeader()
vh.setDefaultSectionSize(row_height)
if click_handler != None:
self._click_handler = click_handler
self.itemClicked.connect(self.item_click_action)
if stretch_last:
hh = self.horizontalHeader()
hh.setStretchLastSection(True)
self.roundit = roundit
self.header_rows = header_rows
示例4: _populateforums
# 需要导入模块: from PySide.QtGui import QTableWidgetItem [as 别名]
# 或者: from PySide.QtGui.QTableWidgetItem import setData [as 别名]
def _populateforums(self):
"""Populates the forums tables (live and archived filters)."""
self.tableForums.clear()
forums = FourChanForum.forums()
sortedforums = sorted(forums, key = lambda x: x)
tables = (self.tableForums, self.tableForumFilter)
for table in tables:
table.setRowCount(len(forums))
table.setColumnCount(2)
i = 0
for short in sortedforums:
data = forums[short]
i1 = QTableWidgetItem(short)
i2 = QTableWidgetItem(data[1])
i1.setData(Qt.UserRole, data)
i2.setData(Qt.UserRole, data)
table.setItem(i, 0, i1)
table.setItem(i, 1, i2)
i += 1
示例5: setData
# 需要导入模块: from PySide.QtGui import QTableWidgetItem [as 别名]
# 或者: from PySide.QtGui.QTableWidgetItem import setData [as 别名]
def setData(self, role, value):
""" Set Data in Item """
if role == Qt.EditRole:
dataSaved = self.saveData(value)
if dataSaved:
for callback in self.callbacks:
callback()
if self.shouldSetData(role):
try:
return QTableWidgetItem.setData(self, role, self.getData())
except RuntimeError:
pass
示例6: QApplication
# 需要导入模块: from PySide.QtGui import QTableWidgetItem [as 别名]
# 或者: from PySide.QtGui.QTableWidgetItem import setData [as 别名]
app = QApplication(sys.argv)
# Create and populate the tableWidget
tableWidget = QTableWidget(4, 4)
tableWidget.setItemDelegate(StarDelegate())
tableWidget.setEditTriggers(QAbstractItemView.DoubleClicked |
QAbstractItemView.SelectedClicked)
tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
tableWidget.setHorizontalHeaderLabels(["Title", "Genre", "Artist", "Rating"])
data = [ ["Mass in B-Minor", "Baroque", "J.S. Bach", 5],
["Three More Foxes", "Jazz", "Maynard Ferguson", 4],
["Sex Bomb", "Pop", "Tom Jones", 3],
["Barbie Girl", "Pop", "Aqua", 5] ]
for r in range(len(data)):
tableWidget.setItem(r, 0, QTableWidgetItem(data[r][0]))
tableWidget.setItem(r, 1, QTableWidgetItem(data[r][1]))
tableWidget.setItem(r, 2, QTableWidgetItem(data[r][2]))
item = QTableWidgetItem()
item.setData(0, StarRating(data[r][3]).starCount)
tableWidget.setItem(r, 3, item)
#tableWidget.resizeColumnsToContents()
tableWidget.resize(500, 300)
tableWidget.show()
sys.exit(app.exec_())