<div dir="ltr"><div>First of all, this is not a PyQt issue.<br></div><div>Then, let's remember that QAbstractItemModel's <span style="font-family:monospace">data()</span> (and <span style="font-family:monospace">headerData()</span>) always return a QVariant, which is a dynamic type object that can be cast/interpreted depending on the implementation.</div><div></div><div>That's why we can, for instance, return a <span style="font-family:monospace">DisplayRole</span> that could be a string, an integer or a float.</div><div><br></div><div>Standard views display a returned <span style="font-family:monospace">DecorationRole</span> value as a QIcon, a QPixmap or even a QImage. The implementation of default delegates is based primarily on the original data type, and eventually behave differently: the default assumption is that the value is a QIcon, therefore they follow the view's <span style="font-family:monospace">iconSize()</span> and provide an appropriate scaled image based on that value (which, according to the <span style="font-family:monospace">pixmap()</span> docs of QIcon, "might be smaller than requested, but never larger"), but if a pixmap or an image is provided, it may be shown at its original size, assuming that the item size allows it, otherwise it's clipped.</div><div><br></div><div>The issue with QHeaderView is based on two aspects:</div><div>1. as the documentation explains, it doesn't use delegates;</div><div>2. the icons normally use the <span style="font-family:monospace">QStyle.PM_SmallIconSize</span> size as reference;<br></div><div>3. it <b>always</b> considers the <span style="font-family:monospace">DecorationRole</span> as a QIcon, therefore (as noted above) it can never be larger than expected;<br></div><div><br></div><div>By checking the sources, the both <span style="font-family:monospace">sectionSizeFromContents()</span> and <span style="font-family:monospace">paintSection()</span> implementations do the following:</div><div><br></div><div><span style="font-family:monospace">const QVariant variant = d->model->headerData(logicalIndex, d->orientation, Qt::DecorationRole);<br>opt.icon = qvariant_cast<QIcon>(variant);<br>if (opt.icon.isNull())<br>    opt.icon = qvariant_cast<QPixmap>(variant);</span></div><div><br></div><div>Therefore, QHeaderView relies on the current style to eventually return an appropriate size for each section, and then display a related "icon" based on the style implementation.</div><div>And while it's up to the style to eventually decide the section size based on the contents, that's not an assumption that can be normally assumed simply based on the <span style="font-family:monospace">DecorationRole</span>: the style only receives a QIcon without a specific context (except for the <span style="font-family:monospace">iconSize()</span> it can get from the view). QIcons can contain any "available size", and there's no way to know if the given QIcon should be assumed as a pixmap returned from the model that should be shown at its original size, or if it's just a QIcon that only has one specified size.</div><div><br></div><div>So, the result is that you will always get an icon with a size that is equal or smaller than the style "small icon size" or the size explicitly set on the header (assuming the style respects it, and it normally doesn't), but never larger than it.</div><div><br></div><div>If you want to have larger icon sizes, then your only options are to use a custom QProxyStyle for the header (or any relevant parent) that eventually returns appropriate sizes for the related CT_HeaderSection), or subclass QHeaderView and eventually implement everything based on your needs.</div><div><br></div><div>Regards,</div><div>MaurizioB<br></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">Il giorno dom 19 ott 2025 alle ore 22:08 John Sturtz <<a href="mailto:john@sturtz.org">john@sturtz.org</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg-7292979154030707638">
<div>Hello again.<div><br></div><div>Attached is a short bit of code that displays a <font face="Consolas">QTableView</font> with a custom <font style="font-size:16px" size="3" face="Consolas">QHeaderView</font>.  The <font style="font-size:16px" size="3" face="Consolas">.headerData()</font> method loads a 64x64 PNG and returns it for <font style="font-size:16px" size="3" face="Consolas">DecorationRole</font>.</div><div><br></div><div>Can anyone tell me why the <font style="font-size:16px" size="3" face="Consolas">.scaled()</font> call on line #61 can't make the header image larger?  If I change the argument to <font style="font-size:16px" size="3" face="Consolas">.scaled()</font> to <font style="font-size:16px" size="3" face="Consolas">QSize(8, 8)</font>, it makes the image small.  So the <font style="font-size:16px" size="3" face="Consolas">.scaled()</font> call is evidently having an effect.  But if I specify <font style="font-size:16px" size="3" face="Consolas">QSize(64, 64)</font>, it doesn't get anywhere near as large as 64x64.  I've been unable to determine why.</div><div><br></div><div>Thanks!</div><div><br></div><div>/John</div></div></div></blockquote></div><div><br clear="all"></div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br><a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div>