Sorting in pyqt tablewidget

Its sorting alpha-numerically (so, in terms of strings, ‘1’, ’10’, ’11’, ’12’, ‘2’, ’20’, ’21’, ’22’, ‘3’, ‘4’ etc. is the proper sort order. It appears that for a QTableWidgetItem, if you use the setData(Qt.EditRole, value) method, the sort order will work. Depending on your version of Qt (I assume) you may have to overload … Read more

pyqt – populating QTableWidget with csv data

Looks like you could use the csv module here: #!/usr/bin/env python #-*- coding:utf-8 -*- import csv import sip sip.setapi(‘QString’, 2) sip.setapi(‘QVariant’, 2) from PyQt4 import QtGui, QtCore class MyWindow(QtGui.QWidget): def __init__(self, fileName, parent=None): super(MyWindow, self).__init__(parent) self.fileName = fileName self.model = QtGui.QStandardItemModel(self) self.tableView = QtGui.QTableView(self) self.tableView.setModel(self.model) self.tableView.horizontalHeader().setStretchLastSection(True) self.pushButtonLoad = QtGui.QPushButton(self) self.pushButtonLoad.setText(“Load Csv File!”) self.pushButtonLoad.clicked.connect(self.on_pushButtonLoad_clicked) self.pushButtonWrite = … Read more

How to make a column in QTableWidget read only?

Insert into the QTableWidget following kind of items: QTableWidgetItem *item = new QTableWidgetItem(); item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); Works fine! EDIT: QTableWidgetItem *item = new QTableWidgetItem(); item->setFlags(item->flags() ^ Qt::ItemIsEditable); This is a better solution. Thanks to @priomsrb.

How to align the text to center of cells in a QTableWidget

This line of code: item = QTableWidgetItem(scraped_age).setTextAlignment(Qt.AlignHCenter) will not work properly, because it throws away the item it creates before assigning it to the variable. The variable will in fact be set to None, which is the return value of setTextAlignment(). Instead, you must do this: item = QTableWidgetItem(scraped_age) # create the item item.setTextAlignment(Qt.AlignHCenter) # … Read more