PDA

View Full Version : QTreeWidget - BUG



George Neil
1st October 2010, 08:45
For my QTreeWidget [say 4 rows and 10 columns]the first column have tree items with icons. Sorting is also enabled for the QTreeWidget

If i just drag the horizontal scroll bar to the right in such a way that the first is not visible. Then try to sort based on a visible column.

Now all the rows height got reduced to a smaller size. This seems to be a QT Bug.

I have attached a UI file for verifying this bug

Is there any workaround for this issue ?

Lykurg
1st October 2010, 09:13
Can't reproduce your problem here. What environment do you use?

George Neil
1st October 2010, 11:31
Can't reproduce your problem here. What environment do you use?

The issue is observed even in QT 4.7.0 in windows

I just attached few snap shots of the Bug.

the issue can be reproduced just by using the QT Designer

George Neil
6th October 2010, 14:27
Is there still any issues in reproducing the issue.

QT experts, Is there any work around ?

wysota
7th October 2010, 01:47
Could you prepare a minimal compilable example reproducing the problem?

ChrisW67
7th October 2010, 02:34
In your screen shot you have icons (32x32 in the UI file) on a few rows other than the first. In your provided UI file you have the uniformRowHeights option turned on. From the doc for QTreeView::uniformRowHeights():

This property should only be set to true if it is guaranteed that all items in the view has the same height. This enables the view to do some optimizations.
The height is obtained from the first item in the view. It is updated when the data changes on that item.
Your application fails on the first point because the icons are clearly taller than the natural/default height for the rows without an icon. The second point means that the first row is used to fix the height, and truncates the icons on subsequent rows, because you have told it that it can make this assumption. When you sort you change the first row and potentially the uniform row height.

Start by turning off that option (or have your model return a better size hint)

George Neil
7th October 2010, 08:30
In your screen shot you have icons (32x32 in the UI file) on a few rows other than the first. In your provided UI file you have the uniformRowHeights option turned on. From the doc for QTreeView::uniformRowHeights():

Your application fails on the first point because the icons are clearly taller than the natural/default height for the rows without an icon. The second point means that the first row is used to fix the height, and truncates the icons on subsequent rows, because you have told it that it can make this assumption. When you sort you change the first row and potentially the uniform row height.

Start by turning off that option (or have your model return a better size hint)
Thanks for the response.

As per your suggestions i just turned off QTreeView::uniformRowHeights().
Also put the same icons for all the Rows.

Still the issue is there !!

If the column with the icons are visible there is no change in the row height and working perfect.

But when the column with the icons are not visible [when we drag the horizontal scroll bar], the row heights are getting reduced.

The modified UI file is also attached here

George Neil
8th October 2010, 12:33
Thanks for the response.

As per your suggestions i just turned off QTreeView::uniformRowHeights().
Also put the same icons for all the Rows.

Still the issue is there !!

If the column with the icons are visible there is no change in the row height and working perfect.

But when the column with the icons are not visible [when we drag the horizontal scroll bar], the row heights are getting reduced.

The modified UI file is also attached here

Experts, Is there any fix to this issue ?

Is there still any difficulty in reproducing the issue ?

wysota
8th October 2010, 13:31
You still didn't provide a minimal compilable example reproducing the problem.

ChrisW67
11th October 2010, 01:00
This shows the behaviour the OP describes (on Linux, Qt 4.6.3):


#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);

// Create a 32x32 icon
QPixmap pixmap(32,32);
QPen pen(Qt::green, 1, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
QPainter painter(&pixmap);
painter.fillRect(QRectF(0,0,32,32), Qt::white);
painter.setPen(pen);
painter.drawRect(QRect(1,1, 30, 30));


QTreeWidget tree;
tree.setColumnCount(10);
tree.setSortingEnabled(true);

for (int row=0; row<10; ++row)
{
QStringList list;
for (int col=0; col<10; ++col)
list << QString("R%1 C%2").arg(row).arg(col);
QTreeWidgetItem *item = new QTreeWidgetItem(&tree, list);
item->setData(0, Qt::DecorationRole, pixmap);
tree.addTopLevelItem(item);
}

tree.show();

return app.exec();
}

If you sort with any part of column zero visible then it works as expected. If column zero is not visible then the sort resizes the row height and truncates the icons.