QTableWidgetItem - type
-
Hi,
I am fiiling a
QTableWidgetwith data while theQTableWidgetItems are generated by two different ways.self.ui.tableEntries.setItem(0, ABVF.BESCHREIBUNG, QTableWidgetItem("any text"))and
witem = QTableWidgetItem(locale.format_string("%.2f", 3.14159, True, True)) witem.setTextAlignment(Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignRight) self.ui.tableEntries.setItem(0, ABVF.AUSGABE, witem)When I then want to access the items by another method
self.ui.tableEntries.item(0, ABVF.BESCHREIBUNG).data(Qt.ItemDataRole.DisplayRole) self.ui.tableEntries.item(0, ABVF.AUSGABE).data(Qt.ItemDataRole.DisplayRole)I get errors.
For column
ABVF.BESCHREIBUNGeverything works fine, for columnABVF.AUSGABEI getAttributeError: 'NoneType' object has no attribute 'data'. This depends not on the column index, since I have more than one column set by each way. If theQTableWidgetItemis created directly in thesetItem-method is different as if created separately.Why is
QTableWidgetItemfor columnABVF.AUSGABEaNoneType?All data are shown correctly in the table! No column is missing, all cells are filled!
The constructor of
QTableWidgetItemhas a default parametertype:int. What is meant by that parameter? Is this one ofQTabWidgetItem.ItemType? Tryingwitem = QTableWidgetItem(locale.format_string("%.2f", 3.15149, True, True), QTableWidgetItem.ItemType.Type)changes nothing.
--EDIT:--
it is coming from
locale.string_format. I have still no clue why. -
OK, I found my mistake.
It is not because of
locale.string_format. Two of the columns are to separated positive and negative values. One is holding all positives and the other all negativs.If a positive value is found I created a
QTableWidgetItemfor the 'positive' column but forgott the create one for the 'negative' column and vice versa.Stupid!
-
Hi,
I am fiiling a
QTableWidgetwith data while theQTableWidgetItems are generated by two different ways.self.ui.tableEntries.setItem(0, ABVF.BESCHREIBUNG, QTableWidgetItem("any text"))and
witem = QTableWidgetItem(locale.format_string("%.2f", 3.14159, True, True)) witem.setTextAlignment(Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignRight) self.ui.tableEntries.setItem(0, ABVF.AUSGABE, witem)When I then want to access the items by another method
self.ui.tableEntries.item(0, ABVF.BESCHREIBUNG).data(Qt.ItemDataRole.DisplayRole) self.ui.tableEntries.item(0, ABVF.AUSGABE).data(Qt.ItemDataRole.DisplayRole)I get errors.
For column
ABVF.BESCHREIBUNGeverything works fine, for columnABVF.AUSGABEI getAttributeError: 'NoneType' object has no attribute 'data'. This depends not on the column index, since I have more than one column set by each way. If theQTableWidgetItemis created directly in thesetItem-method is different as if created separately.Why is
QTableWidgetItemfor columnABVF.AUSGABEaNoneType?All data are shown correctly in the table! No column is missing, all cells are filled!
The constructor of
QTableWidgetItemhas a default parametertype:int. What is meant by that parameter? Is this one ofQTabWidgetItem.ItemType? Tryingwitem = QTableWidgetItem(locale.format_string("%.2f", 3.15149, True, True), QTableWidgetItem.ItemType.Type)changes nothing.
--EDIT:--
it is coming from
locale.string_format. I have still no clue why.@MasterQ
You will get theNoneTypeif there is indeed noQTableWidgetItemat the specified row, column. Either of the two methods you show should work fine. Consequently please set up a standalone project and test both in (0, 0) and (0, 1) respectively. If that goes wrong please post your exact, minimal code. -
Hi,
I am fiiling a
QTableWidgetwith data while theQTableWidgetItems are generated by two different ways.self.ui.tableEntries.setItem(0, ABVF.BESCHREIBUNG, QTableWidgetItem("any text"))and
witem = QTableWidgetItem(locale.format_string("%.2f", 3.14159, True, True)) witem.setTextAlignment(Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignRight) self.ui.tableEntries.setItem(0, ABVF.AUSGABE, witem)When I then want to access the items by another method
self.ui.tableEntries.item(0, ABVF.BESCHREIBUNG).data(Qt.ItemDataRole.DisplayRole) self.ui.tableEntries.item(0, ABVF.AUSGABE).data(Qt.ItemDataRole.DisplayRole)I get errors.
For column
ABVF.BESCHREIBUNGeverything works fine, for columnABVF.AUSGABEI getAttributeError: 'NoneType' object has no attribute 'data'. This depends not on the column index, since I have more than one column set by each way. If theQTableWidgetItemis created directly in thesetItem-method is different as if created separately.Why is
QTableWidgetItemfor columnABVF.AUSGABEaNoneType?All data are shown correctly in the table! No column is missing, all cells are filled!
The constructor of
QTableWidgetItemhas a default parametertype:int. What is meant by that parameter? Is this one ofQTabWidgetItem.ItemType? Tryingwitem = QTableWidgetItem(locale.format_string("%.2f", 3.15149, True, True), QTableWidgetItem.ItemType.Type)changes nothing.
--EDIT:--
it is coming from
locale.string_format. I have still no clue why.@MasterQ said in QTableWidgetItem - type:
it is coming from locale.string_format. I have still no clue why.
Start, as ever, by simplifying. Remove the
, True, True. Try with a format simpler than%.2f. Maybe setlocale.setlocale(locale.LC_ALL, '')before the call. -
OK, I found my mistake.
It is not because of
locale.string_format. Two of the columns are to separated positive and negative values. One is holding all positives and the other all negativs.If a positive value is found I created a
QTableWidgetItemfor the 'positive' column but forgott the create one for the 'negative' column and vice versa.Stupid!
-
M MasterQ has marked this topic as solved on