[Qt-interest] Can't change the Icon size in the HeadView of QTableView!

Andre Somers andre at familiesomers.nl
Wed Aug 25 17:02:47 CEST 2010


  Op 25-8-2010 8:24, bob schreef:
> Hi, All,
>
> When i use QTableView, find can't change the icon size in the HeadView
> of it. The core part of code as follow:
>
> QTableView *pv = new QTableView();
> QStandardItemModel* pm = new QStandardItemModel();
> QStandardItem* pi = new QStandardItem(QIcon("./channel.png"), "hello");
> //the size of png file is 128*128
> pm->setHorizontalHeaderItem(0, pi);
> pv->setModel(pm);
> pv->setGeometry(100, 50, 400, 200);
> pv->setParent(this);
> QHeaderView *ph = pv->horizontalHeader();
> ph->setFixedHeight(80);
> ph->setIconSize(QSize(40,40));
>
> I try to change the size of ph->setIconSize(QSize(40,40)); ,but the size
> of icon don't do any change, why?
>
> BTW:the version is qt-everywhere-opensource-src 4.6.2
>
> Best Regards
Please take a look at the documentation for QHeaderView. In the last 
section of the detailed description, you find the header "Appearance". 
It is detailed that:
1) delegates are not used, even though there is a setDelegate method.
2) only some of the item roles are used; sizeHint not being one of them.

It looks like the only way is to subclass QHeaderView, and reimplement 
the sizeHint and paint methods.

André




More information about the Qt-interest-old mailing list