2 Attachment(s)
Blank rows after populating a QTableWidget
Hi!
Sometimes I get blank rows at end of the QTableWidget after populating data. Look how it looks like:
Attachment 11526
Just after sorting table (clicking over header) the blank rows simply disappear:
Attachment 11527
What could be going on here? I double checked to confirm that I'm not setting wrong values with setRowCount(). Here is the code.
Thanks!
Re: Blank rows after populating a QTableWidget
Dynamic sorting can get confused when adding new records (see note in QSortFilterProxyModel) Try disabling sorting while you add.
Re: Blank rows after populating a QTableWidget
This is a QTableWidget, it is populated manually, not using models. I'm trying other things here, if I have any success I will post here.
Re: Blank rows after populating a QTableWidget
QTableWidget is a QTableView that maintains a model internally for your convenience. The sorting functionality is inherited directly from QTableView and operates on the underlying model Did you actually try disabling sorting?
Re: Blank rows after populating a QTableWidget
Well... It's an intermittent problem, I have to insist on table generation a few times in order to see it happening. I tried using the following:
Code:
ui->tableWidget->setSortingEnabled(false);
//add data
ui->tableWidget->setSortingEnabled(true);
I'm not sure if this method changes the dynamicSortFilter parameter in QSortFilterProxyModel. After a few tries the problem happened again, but now the application also crashes when I close the window after observing the blank rows. When I don't see the blank rows it closes without any issue.
I'm populating this table in two steps. In the first step I have the data to fill only one column, but I'm still creating all the empty QTableWidgetItems for the whole table. In the second step I'm only updating the remaining QTableWidgetItem with setText() or setData(). I'm disabling and enabling sorting before and after each step.
I'm suspecting that the problem is not with the data model, but while drawing the table graphics. I'm saying this because I cannot select the blank rows and after sorting they simply vanish.
Added after 4 minutes:
The only other weird thing I'm seeing in this QTableWidget happens when I call 'QTableWidget->setItem()' at the first time and then I receive the following errors in application output:
QObject::connect: Cannot queue arguments of type 'QVector<int>'
(Make sure 'QVector<int>' is registered using qRegisterMetaType().)
QObject::connect: Cannot queue arguments of type 'QVector<int>'
(Make sure 'QVector<int>' is registered using qRegisterMetaType().)
QObject::connect: Cannot queue arguments of type 'QVector<int>'
(Make sure 'QVector<int>' is registered using qRegisterMetaType().)
QObject::connect: Cannot queue arguments of type 'QVector<int>'
(Make sure 'QVector<int>' is registered using qRegisterMetaType().)
QObject::connect: Cannot queue arguments of type 'QVector<int>'
(Make sure 'QVector<int>' is registered using qRegisterMetaType().)
I don't how it could be related, maybe a coincidence, but I'm setting a QString:
Code:
QString nextSufix
= nextVariable.
OID.
right(nextVariable.
OID.
size() - this
->OIDs.
first().
size());
//add hidden column for index/sufix