#include <QtGui>
int main(int argc, char *argv[])
{
// Create a 32x32 icon
QPen pen
(Qt
::green,
1, Qt
::SolidLine, Qt
::SquareCap, Qt
::MiterJoin);
painter.
fillRect(QRectF(0,
0,
32,
32), Qt
::white);
painter.setPen(pen);
painter.
drawRect(QRect(1,
1,
30,
30));
tree.setColumnCount(10);
tree.setSortingEnabled(true);
for (int row=0; row<10; ++row)
{
for (int col=0; col<10; ++col)
list <<
QString("R%1 C%2").
arg(row
).
arg(col
);
item->setData(0, Qt::DecorationRole, pixmap);
tree.addTopLevelItem(item);
}
tree.show();
return app.exec();
}
#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();
}
To copy to clipboard, switch view to plain text mode
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.
Bookmarks