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


Python QTableWidgetItem.setBackground方法代码示例

本文整理汇总了Python中PySide.QtGui.QTableWidgetItem.setBackground方法的典型用法代码示例。如果您正苦于以下问题:Python QTableWidgetItem.setBackground方法的具体用法?Python QTableWidgetItem.setBackground怎么用?Python QTableWidgetItem.setBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PySide.QtGui.QTableWidgetItem的用法示例。


在下文中一共展示了QTableWidgetItem.setBackground方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: appendTable

# 需要导入模块: from PySide.QtGui import QTableWidgetItem [as 别名]
# 或者: from PySide.QtGui.QTableWidgetItem import setBackground [as 别名]
	def appendTable(self, header, ws):
		try:
			font  = QFont('TypeWriter', pointSize = 10, weight=QFont.Bold)
			for text in header:
				self.table.insertColumn(0)
			for c in xrange(len(header)):
				det = self.determine(header[c])
				item = QTableWidgetItem(header[c])
				if det == 0:
					item.setBackground(QBrush(QColor('#FF8D00')))
				else:
					item.setBackground(QBrush(QColor('#005588')))
				item.setFont(font)
				item.setTextAlignment(Qt.AlignCenter)
				self.table.setItem(0, c, item)	

				nComboBox = self.newCombo()
				nComboBox.setCurrentIndex(det)
				self.table.setCellWidget(1, c, (nComboBox))
				
				for r in xrange(2,26,1):
					item = QTableWidgetItem(ws[c][r-2])
					item.setFont(font)
					item.setTextAlignment(Qt.AlignCenter)
					self.table.setItem(r, c, item)
			self.addStatus(  u'  狀態:  勤務表預覽成功', -1)
			return 0
		except:
			self.addStatus(  u'  狀態:  勤務表預覽失敗', 1)
			return 'error'
开发者ID:s910324,项目名称:AutoSchedule,代码行数:32,代码来源:AutoSchedule.py

示例2: __init__

# 需要导入模块: from PySide.QtGui import QTableWidgetItem [as 别名]
# 或者: from PySide.QtGui.QTableWidgetItem import setBackground [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

示例3: updateSentenceView

# 需要导入模块: from PySide.QtGui import QTableWidgetItem [as 别名]
# 或者: from PySide.QtGui.QTableWidgetItem import setBackground [as 别名]
    def updateSentenceView(self):
        """
        Updates a sentence view.
        """
        sections = self.selectedTitles(self.ui.listWidgetSection.selectedItems())
        sub_sections =  self.selectedTitles(self.ui.listWidgetSubSection.selectedItems())
        functions =  self.selectedTitles(self.ui.listWidgetFunction.selectedItems())       
        sentences = self.container.listSentences(section=list(sections),subsection=list(sub_sections),function=list(functions))
        
        self.ui.tableWidgetSentence.clear()
        self.ui.tableWidgetSentence.setColumnCount(5)
        
        self.ui.tableWidgetSentence.setHorizontalHeaderItem(0,QTableWidgetItem('Section'))
        self.ui.tableWidgetSentence.setHorizontalHeaderItem(1,QTableWidgetItem('Sub Section'))
        self.ui.tableWidgetSentence.setHorizontalHeaderItem(2,QTableWidgetItem('Function'))
        self.ui.tableWidgetSentence.setHorizontalHeaderItem(3,QTableWidgetItem('Sentence'))
        self.ui.tableWidgetSentence.setHorizontalHeaderItem(4,QTableWidgetItem('Reference'))
        
        self.ui.tableWidgetSentence.setColumnWidth(0,150)
        self.ui.tableWidgetSentence.setColumnWidth(1,200)
        self.ui.tableWidgetSentence.setColumnWidth(2,300)
        self.ui.tableWidgetSentence.setColumnWidth(3,900)
        self.ui.tableWidgetSentence.setColumnWidth(4,100)  

        row = 0
        strip = self.ui.checkBoxStrip.isChecked()

        for secv, subsv, funcv, sentv, refv in sentences:
            if sentv != u'NULL':

                sec_item = QTableWidgetItem(str(secv))
                subs_item = QTableWidgetItem(str(subsv))
                func_item = QTableWidgetItem(str(funcv))
                sent_item = QTableWidgetItem(str(sentv))
                ref_item = QTableWidgetItem(str(refv))
                
                self.ui.tableWidgetSentence.setItem(row,0,sec_item)
                self.ui.tableWidgetSentence.setItem(row,1,subs_item)
                self.ui.tableWidgetSentence.setItem(row,2,func_item)
                self.ui.tableWidgetSentence.setItem(row,3,sent_item)
                self.ui.tableWidgetSentence.setItem(row,4,ref_item)
                
                if strip:
                    try:
                        sent_item.setText(str(self.adjustSentence(sentv, "{", "}", False, "...")))
                    except Exception:
                        sent_item.setText(str(sentv))
                        # Background red
                        sent_item.setBackground(QBrush(QColor(255,0,0,127)))
                row += 1
                
        self.ui.labelShownSentence.setText(str(row))
        
        self.ui.tableWidgetSentence.setRowCount(row)
        
        self.ui.tableWidgetSentence.setColumnHidden(0, \
            not self.ui.checkBoxSection.isChecked())
        self.ui.tableWidgetSentence.setColumnHidden(1, \
            not self.ui.checkBoxSubSection.isChecked())
        self.ui.tableWidgetSentence.setColumnHidden(2, \
            not self.ui.checkBoxFunction.isChecked())
        self.ui.tableWidgetSentence.setColumnHidden(4, \
            not self.ui.checkBoxReference.isChecked())
开发者ID:dpizetta,项目名称:sci-corpus,代码行数:65,代码来源:sci_corpus_main.py


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