本文整理汇总了Python中PySide.QtGui.QTableWidgetItem.setText方法的典型用法代码示例。如果您正苦于以下问题:Python QTableWidgetItem.setText方法的具体用法?Python QTableWidgetItem.setText怎么用?Python QTableWidgetItem.setText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QTableWidgetItem
的用法示例。
在下文中一共展示了QTableWidgetItem.setText方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _addTableItem
# 需要导入模块: from PySide.QtGui import QTableWidgetItem [as 别名]
# 或者: from PySide.QtGui.QTableWidgetItem import setText [as 别名]
def _addTableItem(self, row, col, text=None):
tableItem = QTableWidgetItem()
if text is not None:
tableItem.setText(text)
self.table.setItem(row, col, tableItem)
return tableItem
示例2: insert_row
# 需要导入模块: from PySide.QtGui import QTableWidgetItem [as 别名]
# 或者: from PySide.QtGui.QTableWidgetItem import setText [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 setText [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: updateSentenceView
# 需要导入模块: from PySide.QtGui import QTableWidgetItem [as 别名]
# 或者: from PySide.QtGui.QTableWidgetItem import setText [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())
示例5: Ui_MainWindow
# 需要导入模块: from PySide.QtGui import QTableWidgetItem [as 别名]
# 或者: from PySide.QtGui.QTableWidgetItem import setText [as 别名]
class Ui_MainWindow(QMainWindow):
"""Cette classe contient tous les widgets de notre application."""
defaultPalette = QPalette()
defaultPalette.setColor(QPalette.Base, QColor("#151515"))
defaultPalette.setColor(QPalette.Text, Qt.white)
def __init__(self):
super(Ui_MainWindow, self).__init__()
# initialise la GUI avec un exemple
self.text = "Ceci est un petit texte d'exemple."
# les variables sont en place, initialise la GUI
self.initUI()
# exécute l'exemple
self.orgText.setText(self.text)
self.encode_text(False)
self.logLab.setText(
u"Saisir du texte ou importer un fichier, puis pousser \n"
u"le bouton correspondant à l'opération souhaitée.")
def initUI(self):
"""Met en place les éléments de l'interface."""
# -+++++++------------------- main window -------------------+++++++- #
self.setWindowTitle(u"Encodage / Décodage de Huffman")
self.centerAndResize()
centralwidget = QWidget(self)
mainGrid = QGridLayout(centralwidget)
mainGrid.setColumnMinimumWidth(0, 450)
# -+++++++------------------ groupe analyse -----------------+++++++- #
analysGroup = QGroupBox(u"Analyse", centralwidget)
self.analysGrid = QGridLayout(analysGroup)
# ----------- groupe de la table des codes ---------- #
codeTableGroup = QGroupBox(u"Table des codes", analysGroup)
codeTableGrid = QGridLayout(codeTableGroup)
# un tableau pour les codes
self.codesTableModel = MyTableModel()
self.codesTable = QTableView(codeTableGroup)
self.codesTable.setModel(self.codesTableModel)
self.codesTable.setFont(QFont("Mono", 8))
self.codesTable.resizeColumnsToContents()
self.codesTable.setSortingEnabled(True)
codeTableGrid.addWidget(self.codesTable, 0, 0, 1, 1)
self.analysGrid.addWidget(codeTableGroup, 1, 0, 1, 1)
# ----------- label du ratio de compression ---------- #
self.ratioLab = QLabel(u"Ratio de compression: ", analysGroup)
font = QFont()
font.setBold(True)
font.setWeight(75)
font.setKerning(True)
self.ratioLab.setFont(font)
self.analysGrid.addWidget(self.ratioLab, 2, 0, 1, 1)
# -+++++++-------- groupe de la table de comparaison --------+++++++- #
self.compGroup = QGroupBox(analysGroup)
self.compGroup.setTitle(u"Comparaisons")
compGrid = QGridLayout(self.compGroup)
# un tableau pour le ratio
self.compTable = QTableWidget(self.compGroup)
sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(
self.compTable.sizePolicy().hasHeightForWidth())
self.compTable.setSizePolicy(sizePolicy)
self.compTable.setBaseSize(QSize(0, 0))
font = QFont()
font.setWeight(50)
self.compTable.setFont(font)
self.compTable.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.compTable.setShowGrid(True)
self.compTable.setGridStyle(Qt.SolidLine)
# lignes / colonnes
self.compTable.setColumnCount(2)
self.compTable.setRowCount(3)
self.compTable.setVerticalHeaderItem(0, QTableWidgetItem("Taille (bits)"))
self.compTable.setVerticalHeaderItem(1, QTableWidgetItem("Entropie"))
self.compTable.setVerticalHeaderItem(2, QTableWidgetItem("Taille moy. (bits)"))
for i in range(2):
self.compTable.verticalHeaderItem(i).setTextAlignment(
Qt.AlignRight)
self.compTable.setHorizontalHeaderItem(0, QTableWidgetItem("ASCII"))
self.compTable.setHorizontalHeaderItem(1, QTableWidgetItem("Huffman"))
# nom des items
self.compTabASCIIMem = QTableWidgetItem()
self.compTable.setItem(0, 0, self.compTabASCIIMem)
self.compTabASCIIEnt = QTableWidgetItem()
self.compTable.setItem(1, 0, self.compTabASCIIEnt)
self.compTabASCIIAvg = QTableWidgetItem()
self.compTable.setItem(2, 0, self.compTabASCIIAvg)
self.compTabHuffMem = QTableWidgetItem()
self.compTable.setItem(0, 1, self.compTabHuffMem)
self.compTabHuffEnt = QTableWidgetItem()
self.compTable.setItem(1, 1, self.compTabHuffEnt)
self.compTabHuffAvg = QTableWidgetItem()
self.compTable.setItem(2, 1, self.compTabHuffAvg)
# parem du tableau
self.compTable.horizontalHeader().setCascadingSectionResizes(False)
self.compTable.verticalHeader().setVisible(True)
font = QFont("Mono", 8)
self.compTable.setFont(font)
#.........这里部分代码省略.........