
Originally Posted by
VireX
Yep, see you can see the bug too.
But that particular bug is in your code.
Look:
...
qt->setSortingEnabled(true);
qt->sortItems(0, Qt::AscendingOrder);
...
for(int i = 0; i < 75; i++){
qt->setItem(i, 0, ax[i]);
}
...
...
qt->setSortingEnabled(true);
qt->sortItems(0, Qt::AscendingOrder);
...
for(int i = 0; i < 75; i++){
ax[i] = new QTableWidgetItem(QString("Ebeeef%1").arg(i));
qt->setItem(i, 0, ax[i]);
qt->setCellWidget(i, 0, new QPushButton("ff"));
}
...
To copy to clipboard, switch view to plain text mode
First you tell Qt to sort all of the items alphabetically and then you add them in non-alphabetical order, so Qt has to sort the items after every setItem(). In result you invoke setCellWidget() either zero or more than once on certain cells.
The proper way to do it is:
for(int i = 0; i < 75; i++){
qt->setItem(i, 0, ax[i]);
qt
->setCellWidget
(ax
[i
]->row
(),
0,
new QPushButton("ff"));
}
for(int i = 0; i < 75; i++){
ax[i] = new QTableWidgetItem(QString("Ebeeef%1").arg(i));
qt->setItem(i, 0, ax[i]);
qt->setCellWidget(ax[i]->row(), 0, new QPushButton("ff"));
}
To copy to clipboard, switch view to plain text mode
It works fine on Qt 4.2.3, but on Qt 4.3.0 there's indeed some problem with cell widgets and sorting.
Bookmarks