Xiangru Lian
Xiangru Lian

Reputation: 968

How to change the accuracy of a floating point number in a cell in QTableWidget?

Here is part of my code:

cell = QtWidgets.QTableWidgetItem()
cell.setData(QtCore.Qt.EditRole, dics[0][key])
self.data_row_selection_table.setItem(row, nmr_analysis.QT_DATA_COLUMN_ENTRIES.index(key), cell)

the application appears likeenter image description here

But when I edit the cell, the number's accuracy is limited to centile: enter image description here

How to change the displayed precision of the numbers as well as the limited accuracy during edit?

Upvotes: 1

Views: 1340

Answers (1)

NoDataDumpNoContribution
NoDataDumpNoContribution

Reputation: 10859

One way is to make your own model (derived from QAbstractTableModel) and then in the data method convert floating point numbers to the desired precision with '{.xf}'.format(number) or similar. This should also lift the edit restrictions.

When you retrieve the data from the model you would have to convert to numbers again.

Upvotes: 2

Related Questions