简体   繁体   中英

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 like 在此处输入图片说明

But when I edit the cell, the number's accuracy is limited to centile: 在此处输入图片说明

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM