Results 1 to 8 of 8

Thread: QTableWidget won't sort cellwidgets!!!

  1. #1
    Join Date
    Jul 2007
    Posts
    30
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Arrow QTableWidget won't sort cellwidgets!!!

    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:

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6. qt->verticalHeader()->setVisible(false);
    7. qt->setRowCount(85);
    8. qt->setColumnCount(4);
    9. qt->setSortingEnabled(false);
    10. QTableWidgetItem *__colItem = new QTableWidgetItem();
    11. __colItem->setText(QApplication::translate("t", "t1", 0, QApplication::UnicodeUTF8));
    12. qt->setHorizontalHeaderItem(0, __colItem);
    13. QTableWidgetItem *__colItem2 = new QTableWidgetItem();
    14. __colItem2->setText(QApplication::translate("t", "t2", 0, QApplication::UnicodeUTF8));
    15. qt->setHorizontalHeaderItem(1, __colItem2);
    16. QTableWidgetItem *__colItem3 = new QTableWidgetItem();
    17. __colItem3->setText(QApplication::translate("t", "t3", 0, QApplication::UnicodeUTF8));
    18. qt->setHorizontalHeaderItem(2, __colItem3);
    19. QTableWidgetItem *__colItem4 = new QTableWidgetItem();
    20. __colItem4->setText(QApplication::translate("t", "t4", 0, QApplication::UnicodeUTF8));
    21. qt->setHorizontalHeaderItem(2, __colItem4);
    22. QTableWidgetItem* ax2[75];
    23. QTableWidgetItem* ax3[75];
    24. QTableWidgetItem* ax4[75];
    25. QString num;
    26. for(int i = 0; i < 75; i++){
    27. if(i < 10){
    28. num = QString("0%1").arg(i);
    29. } else {
    30. num = QString("%1").arg(i);
    31. }
    32. //if(isSortingEnabled()) ==== false!!!!
    33. ax[i] = new QTableWidgetItem(QString("QA%1").arg(num));
    34. ax2[i] = new QTableWidgetItem(QString("QB%1").arg(num));
    35. ax3[i] = new QTableWidgetItem(QString("QC%1").arg(num));
    36. ax4[i] = new QTableWidgetItem(QString("QD%1").arg(num));
    37. qt->setItem(i, 0, ax[i]);
    38. qt->setCellWidget(qt->row(ax[i]), 0, new QPushButton(QString("QA%1").arg(num)));
    39. qt->setItem(qt->row(ax[i]), 1, ax2[i]);
    40. qt->setCellWidget(qt->row(ax[i]), 1, new QPushButton(QString("QB%1").arg(num)));
    41. qt->setItem(qt->row(ax[i]), 2, ax3[i]);
    42. qt->setItem(qt->row(ax[i]), 3, ax4[i]);
    43. }
    44. qt->setSortingEnabled(true);
    45. //qt->sortItems(0, Qt::AscendingOrder);
    46. qt->sortByColumn(0, Qt::AscendingOrder);
    47. qt->show();
    48. return app.exec();
    49. }
    To copy to clipboard, switch view to plain text mode 

    Thank you for your help!

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget won't sort cellwidgets!!!

    Indeed, I reproduced your issue, and I found this on Trolltech's Task Tracker.

    http://trolltech.com/developer/task-...ntry&id=166714

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

  3. #3
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget won't sort cellwidgets!!!

    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.
    Last edited by guilugi; 9th July 2007 at 10:00.

  4. #4
    Join Date
    Jul 2007
    Posts
    30
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget won't sort cellwidgets!!!

    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???
    Last edited by Arsenic; 9th July 2007 at 17:42.

  5. #5
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget won't sort cellwidgets!!!

    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.

  6. #6
    Join Date
    Jul 2007
    Posts
    30
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget won't sort cellwidgets!!!

    I posted it, but I wish we can find some sort of easy work-around for it, maybe wysota or jpn knows how.

  7. #7
    Join Date
    Jul 2007
    Posts
    30
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget won't sort cellwidgets!!!

    I think they fixed it in 4.3.1, but I cant compile that crap. They dont allow you to compile it.

  8. #8
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget won't sort cellwidgets!!!

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.