PDA

View Full Version : QTableWidget won't sort cellwidgets!!!



Arsenic
9th July 2007, 09:45
Well I was coding some things, and I discovered that sorting doesn't work in Qt 4.3.0, for some reason I am doing something wrong, and I tried every method. But it seems that buttons disappear when you sort a widget even if sorting was disabled when adding items.

Does anyone have a solution or workaround for this? I tried adding just with i, or with qt->row(item) or with qt->row() but results haven't changed. I also notice, that it seems to only happen for rows 2,3 82 and 83. It's quite wierd.

Take a look and try this example code:



#include <QtGui>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTableWidget* qt = new QTableWidget;
qt->verticalHeader()->setVisible(false);
qt->setRowCount(85);
qt->setColumnCount(4);
qt->setSortingEnabled(false);
QTableWidgetItem *__colItem = new QTableWidgetItem();
__colItem->setText(QApplication::translate("t", "t1", 0, QApplication::UnicodeUTF8));
qt->setHorizontalHeaderItem(0, __colItem);
QTableWidgetItem *__colItem2 = new QTableWidgetItem();
__colItem2->setText(QApplication::translate("t", "t2", 0, QApplication::UnicodeUTF8));
qt->setHorizontalHeaderItem(1, __colItem2);
QTableWidgetItem *__colItem3 = new QTableWidgetItem();
__colItem3->setText(QApplication::translate("t", "t3", 0, QApplication::UnicodeUTF8));
qt->setHorizontalHeaderItem(2, __colItem3);
QTableWidgetItem *__colItem4 = new QTableWidgetItem();
__colItem4->setText(QApplication::translate("t", "t4", 0, QApplication::UnicodeUTF8));
qt->setHorizontalHeaderItem(2, __colItem4);
QTableWidgetItem* ax[75];
QTableWidgetItem* ax2[75];
QTableWidgetItem* ax3[75];
QTableWidgetItem* ax4[75];
QString num;
for(int i = 0; i < 75; i++){
if(i < 10){
num = QString("0%1").arg(i);
} else {
num = QString("%1").arg(i);
}
//if(isSortingEnabled()) ==== false!!!!
ax[i] = new QTableWidgetItem(QString("QA%1").arg(num));
ax2[i] = new QTableWidgetItem(QString("QB%1").arg(num));
ax3[i] = new QTableWidgetItem(QString("QC%1").arg(num));
ax4[i] = new QTableWidgetItem(QString("QD%1").arg(num));
qt->setItem(i, 0, ax[i]);
qt->setCellWidget(qt->row(ax[i]), 0, new QPushButton(QString("QA%1").arg(num)));
qt->setItem(qt->row(ax[i]), 1, ax2[i]);
qt->setCellWidget(qt->row(ax[i]), 1, new QPushButton(QString("QB%1").arg(num)));
qt->setItem(qt->row(ax[i]), 2, ax3[i]);
qt->setItem(qt->row(ax[i]), 3, ax4[i]);
}
qt->setSortingEnabled(true);
//qt->sortItems(0, Qt::AscendingOrder);
qt->sortByColumn(0, Qt::AscendingOrder);
qt->show();
return app.exec();
}


Thank you for your help!

guilugi
9th July 2007, 10:23
Indeed, I reproduced your issue, and I found this on Trolltech's Task Tracker.

http://trolltech.com/developer/task-tracker/index_html?method=entry&id=166714

I'm currently looking at your code to see if there's something wrong ;-)

guilugi
9th July 2007, 10:39
Ok , seems it's messy when you implement everything in main..

I changed a little your code, just adding a subclass of QTableWidget, and now it works fine

EDIT : ooops, no, it doesn't work either...I remove the attachment...maybe you could provide this sample to Task Tracker, to me it seems like a bug.

Arsenic
9th July 2007, 18:37
They seem to have rejected that bug, like as if it's not a bug, they tell me how to properly use it in the tracker, but then I guess they never tested their own code or were in a hurry.

Can someone send another tracker and update that?

Is there a more complex way like overriding the sort method, or perhaps looking into 4.3.1 source code, and seeing how they fixed it maybe???

guilugi
9th July 2007, 18:43
Well, I think you can repost, because I think your bug is different.

They precise in their report that you musn't enable table sorting while(or before) you add cell widgets...but in this case, you enable it only after items have been inserted...

That's why I think you can re-post...and refer to the previous bug that has been rejected !

Guilugi.

Arsenic
9th July 2007, 21:14
I posted it, but I wish we can find some sort of easy work-around for it, maybe wysota or jpn knows how.

Arsenic
21st July 2007, 04:48
I think they fixed it in 4.3.1, but I cant compile that crap. They dont allow you to compile it.

guilugi
21st July 2007, 11:41
I think patience may be the best right now : I don't know the actual state of 4.3.1, but it should come out as an official release soon enough :)