当前位置: 首页>>代码示例>>Python>>正文


Python QTableWidgetItem.setData方法代码示例

本文整理汇总了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
开发者ID:elricbk,项目名称:pyenvelopes,代码行数:9,代码来源:MainForm.py

示例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)
开发者ID:bsherin,项目名称:shared_tools,代码行数:13,代码来源:qanalysis_window_basics.py

示例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
开发者ID:bsherin,项目名称:shared_tools,代码行数:54,代码来源:qanalysis_window_basics.py

示例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
开发者ID:Hydrael,项目名称:4ca,代码行数:21,代码来源:mainwindow.py

示例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
开发者ID:cloew,项目名称:PersonalAccountingSoftware,代码行数:14,代码来源:kao_table_item.py

示例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_())
                   
开发者ID:yoann01,项目名称:bullseye,代码行数:31,代码来源:stardelegate.py


注:本文中的PySide.QtGui.QTableWidgetItem.setData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。