Hide the border of the selected cell in qtablewidget in pyqt?
I prefer to do: ui->tableWidget->setFocusPolicy(Qt::NoFocus); You can also change the focus policy using the design tab.
I prefer to do: ui->tableWidget->setFocusPolicy(Qt::NoFocus); You can also change the focus policy using the design tab.
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
Here a test script which compares a few ways of populating a table. The custom model is much faster, because it does not have to create all the items up front – but note that it is a very basic implementation, so does not implement sorting, editing, etc. (See Model/View Programming for more details). from … Read more
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
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.
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