Why does Qt add more than three columns when I use restoreState() on a QTableWidget?

StackOverflow https://stackoverflow.com/questions/915352

  •  06-09-2019
  •  | 
  •  

Question

My code looks somehow like the following:

table = QTableWidget()
table.horizontalHeader().restoreState(settings.value("savedState"))
table.setColumnCount(3)

settings.setValue("savedState", table.horizontalHeader().saveState())

If I run it the first time it there are only 3 column headers. The second time there are 6 and the third 9... The strange thing is table.columnCount() is always 3. If i remove table.setColumnCount(3) there are no columns at all.

Why is this happening and is it a bug or intentional?

UPDATE

Adding table.clearContents() before table.setColumnCount(3) made it work. I still think it's a bug.

Was it helpful?

Solution

Which platform and what Qt version is this? http://chaos.troll.no/~hhartz/tablecolumns.tar seems to work fine using latest Qt 4.5

OTHER TIPS

What happens with?

table = QTableWidget();
table.setColumnCount(3);
table.horizontalHeader().restoreState(settings.value("savedState"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top