Results 1 to 7 of 7

Thread: Possible QTableWidget bug appeared in new Qt 4.5.3?

  1. #1
    Join Date
    Oct 2009
    Location
    Craiova, Romania
    Posts
    46
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Possible QTableWidget bug appeared in new Qt 4.5.3?

    Hello!

    I am the author of a free software for timetabling, http://lalescu.ro/liviu/fet/

    I have met a problem with latest Qt 4.5.3 (not shown in previous versions of Qt), problem which exists on Linux and on Windows.

    The problem is that if I change data in a QTableWidget using function table->item(row,col)->setText("new text"), the first row of the table is not update until I move the mouse over it. For this, run the attached sample, press the button and see that the first row is not updated until you move mouse over table.

    I have a very small example, attached.

    I found that the bug can be avoided if I write "table->viewport()->update()" after changing of one or more values. But this may consume unnecessary time?

    Maybe you can help me with advice on how to avoid better this bug. It is important that my software works well with Qt 4.5.3 and with future versions.

    I submitted this possible bug to Qt task tracker, but I have not received answer until now.

    I write below the example (it is the same as the archived attachment):

    bug.h:

    Qt Code:
    1. #include <QApplication>
    2.  
    3. #include <QtGui>
    4.  
    5. class Dialog: public QDialog
    6. {
    7. Q_OBJECT
    8.  
    9. public:
    10. QVBoxLayout* layout;
    11. QTableWidget* table;
    12.  
    13. Dialog();
    14. ~Dialog();
    15.  
    16. public slots:
    17. void pbClicked();
    18. };
    To copy to clipboard, switch view to plain text mode 
    bug.cpp:

    Qt Code:
    1. #include "bug.h"
    2.  
    3. #include <QApplication>
    4.  
    5. #include <QtGui>
    6.  
    7. Dialog::Dialog()
    8. {
    9. layout=new QVBoxLayout(this);
    10.  
    11. table=new QTableWidget();
    12.  
    13. pb=new QPushButton("Press me");
    14.  
    15. layout->addWidget(table);
    16. layout->addWidget(pb);
    17.  
    18. connect(pb, SIGNAL(clicked()), this, SLOT(pbClicked()));
    19.  
    20. table->setRowCount(5);
    21. table->setColumnCount(5);
    22.  
    23. for(int i=0; i<5; i++)
    24. for(int j=0; j<5; j++){
    25. item->setText("initial");
    26. table->setItem(i, j, item);
    27. }
    28. table->resizeRowsToContents();
    29. }
    30.  
    31. Dialog::~Dialog()
    32. {
    33. }
    34.  
    35. void Dialog::pbClicked()
    36. {
    37. for(int i=0; i<5; i++)
    38. for(int j=0; j<5; j++)
    39. table->item(i,j)->setText(tr("Cell %1,%2 modified").arg(i).arg(j));
    40. }
    41.  
    42. int main(int argc, char** argv)
    43. {
    44. QApplication app(argc, argv);
    45.  
    46. Dialog dialog;
    47. dialog.show();
    48.  
    49. return app.exec();
    50. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files
    Last edited by wysota; 20th October 2009 at 19:33.

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Possible QTableWidget bug appeared in new Qt 4.5.3?

    Works fine for me with Qt 4.5.3.
    I'm a rebel in the S.D.G.

  3. #3
    Join Date
    Oct 2009
    Location
    Craiova, Romania
    Posts
    46
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Possible QTableWidget bug appeared in new Qt 4.5.3?

    Quote Originally Posted by lyuts View Post
    Works fine for me with Qt 4.5.3.
    On what platform? Windows, Linux, Mac? I have AMD64 bit dual core.

    I meant the problem is this: initially, the table has all cells with text "Initial". After you press the button "Press me", all the cells should have the text: "Cell i,j modified". But the first row still shows text "Initial", until you move mouse over table or make some clicks.

  4. #4
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Possible QTableWidget bug appeared in new Qt 4.5.3?

    Yeah, I do understand the actual behavior and the desired one.

    I'm on 32bit Linux, though i don't have AMD.
    I'm a rebel in the S.D.G.

  5. #5
    Join Date
    Oct 2009
    Location
    Craiova, Romania
    Posts
    46
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default

    I tried the same code on another computer, old laptop with Windows XP, I get the same bug. I also get this bug on my computer, GNU/Linux openSUSE 11.1 64 bit.

    Yes, it is a bug, I found it on my computer and I found that they fixed it (by comparing the 4.5.2, 4.5.3 (buggy) and 4.6.0-snapshot (fixed).

    My question: I found a hack to make my program work in Qt 4.5.3. Should I keep this hack only for 4.5.3? It is a time taking step and I don't want to do it unnecessarily.

    Below are the code parts from Qt, if you are interested. They changed from 4.5.3 to 4.6.0 the part of d->viewport->geometry() to d->viewport->rect()

    I found practically with my sample that for instance viewport geometry is: 15,20,100,100 and viewport rect is 0,0,100,100 (so you need to take care of 0,0 and not of 15,20, which is the relative distance to father widget).

    4.5.2 (working OK, probably not optimized):

    Qt Code:
    1. void QAbstractItemView::update(const QModelIndex &index)
    2. {
    3. if (index.isValid())
    4. d->viewport->update(visualRect(index));
    5. }
    To copy to clipboard, switch view to plain text mode 

    4.5.3 (buggy):

    Qt Code:
    1. void QAbstractItemView::update(const QModelIndex &index)
    2. {
    3. if (index.isValid()) {
    4. const QRect rect = visualRect(index);
    5. //this test is important for peformance reason
    6. //For example in dataChanged we simply update all the cells without checking
    7. //it can be a major bottleneck to update rects that aren't even part of the viewport
    8. if (d->viewport->geometry().intersects(rect))
    9. d->viewport->update(rect);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    4.6.0-snapshot (solved):

    Qt Code:
    1. void QAbstractItemView::update(const QModelIndex &index)
    2. {
    3. if (index.isValid()) {
    4. const QRect rect = visualRect(index);
    5. //this test is important for peformance reason
    6. //For example in dataChanged we simply update all the cells without checking
    7. //it can be a major bottleneck to update rects that aren't even part of the viewport
    8. if (d->viewport->rect().intersects(rect))
    9. d->viewport->update(rect);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    http://qt.gitorious.org/qt/qt/commit...48939725c216c8

    is the bug listed on Gitorious.

    So, could you please tell me, can I expect that this bug is only in Qt 4.5.3, so my program works OK?
    Last edited by wysota; 20th October 2009 at 19:35.

  6. #6
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    64
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Possible QTableWidget bug appeared in new Qt 4.5.3?

    I noticed this bug as well using Qt 4.5.3 on OpenSUSE 11.0.

    I use the following workaround:

    Instead of
    Qt Code:
    1. function table->item(row,col)->setText("new text")
    To copy to clipboard, switch view to plain text mode 

    I use
    Qt Code:
    1. ((QLabel *)(function table->cellwidget(row,col)))->setText("new text")
    To copy to clipboard, switch view to plain text mode 

    Ofcourse you have to change your code in such a way that it use QLabels instead of itemtext's.

    Your new code will look like:

    Qt Code:
    1. #include "bug.h"
    2.  
    3. #include <QApplication>
    4.  
    5. #include <QtGui>
    6.  
    7. Dialog::Dialog()
    8. {
    9. layout=new QVBoxLayout(this);
    10.  
    11. table=new QTableWidget();
    12.  
    13. pb=new QPushButton("Press me");
    14.  
    15. layout->addWidget(table);
    16. layout->addWidget(pb);
    17.  
    18. connect(pb, SIGNAL(clicked()), this, SLOT(pbClicked()));
    19.  
    20. table->setRowCount(5);
    21. table->setColumnCount(5);
    22.  
    23. for(int i=0; i<5; i++)
    24. for(int j=0; j<5; j++){
    25. QLabel *label=new QLabel();
    26. label->setText("initial");
    27. table->setCellWidget(i, j, label);
    28. }
    29. table->resizeRowsToContents();
    30. }
    31.  
    32. Dialog::~Dialog()
    33. {
    34. }
    35.  
    36. void Dialog::pbClicked()
    37. {
    38. for(int i=0; i<5; i++)
    39. for(int j=0; j<5; j++)
    40. ((QLabel *)(table->cellWidget(i,j)))->setText(tr("Cell %1,%2 modified").arg(i).arg(j));
    41. }
    42.  
    43. int main(int argc, char** argv)
    44. {
    45. QApplication app(argc, argv);
    46.  
    47. Dialog dialog;
    48. dialog.show();
    49.  
    50. return app.exec();
    51. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Oct 2009
    Location
    Craiova, Romania
    Posts
    46
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Possible QTableWidget bug appeared in new Qt 4.5.3?

    Thanks, Teuniz, but I think your solution to avoid this bug is less convenient (at least for me) than my hack (solution) to avoid this bug.

    Do you think that since they fixed this bug in the repositories, Qt 4.5.3 will remain the only Qt version with this bug? I do not want to apply my hack uselessly, but I want to make sure my program is bug free for future Qt versions.

Similar Threads

  1. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2007, 00:29
  2. QTableWidget (resizing rows, turning off selection, etc.)
    By kiss-o-matic in forum Qt Programming
    Replies: 6
    Last Post: 11th January 2007, 02:57
  3. QTableWidget issues
    By Djony in forum Qt Programming
    Replies: 42
    Last Post: 20th December 2006, 00:27
  4. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 19:46
  5. Replies: 6
    Last Post: 5th March 2006, 22:05

Tags for this Thread

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.