<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QListView : Increasing the cell width and height]]></title><description><![CDATA[<p dir="auto">Hi</p>
<p dir="auto">I'm using the QListView. Each element of the list view is displaying the ICON and Text. We don't have any issue in using it.</p>
<p dir="auto">When the item is selected using up and down arrow keys, I would like to increase the ICON size and Text font size for selected item. How can we do this  ? Any hints or sample program ?</p>
]]></description><link>https://forum.qt.io/topic/56664/qlistview-increasing-the-cell-width-and-height</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 07:54:36 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/56664.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 23 Jul 2015 10:36:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QListView : Increasing the cell width and height on Thu, 23 Jul 2015 14:32:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dheerendra">@<bdi>dheerendra</bdi></a><br />
You are most welcome.<br />
Bear in mind that you might need to support a few more type of drawing if it must support states like<br />
disabled. Also, it does not work with styles/stylesheets without a bit of tweaking.</p>
]]></description><link>https://forum.qt.io/post/283508</link><guid isPermaLink="true">https://forum.qt.io/post/283508</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Thu, 23 Jul 2015 14:32:22 GMT</pubDate></item><item><title><![CDATA[Reply to QListView : Increasing the cell width and height on Thu, 23 Jul 2015 13:21:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> said:</p>
<blockquote>
<p dir="auto">QStyle* style = option.widget ? option.widget-&gt;style() : QApplication::style();<br />
QRect rect = option.rect;</p>
<pre><code>QString thetext = index.model()-&gt;data ( index.model()-&gt;index ( index.row(), 0 ) ).toString();

if ( option.state &amp; QStyle::State_Selected ) {
    painter-&gt;save();
    // draw selection rext
    style-&gt;drawControl ( QStyle::CE_ItemViewItem, &amp;option, painter, option.widget );
    // get icon and scale it
    QIcon icon = qvariant_cast&lt;QIcon&gt; ( index.model()-&gt;data ( index, Qt::DecorationRole ) );
    //scale it . note must be big enough or you get a smaller
    QSize mysize = option.decorationSize;
    mysize.scale ( mysize.width() + 10, mysize.width() + 10, Qt::KeepAspectRatio );
    QPixmap iconPixmap = icon.pixmap ( mysize );
    //draw icon
    painter-&gt;drawPixmap (  option.rect.x() , option.rect.center().y() - mysize.height()/2 , iconPixmap  );        
    // Change font
    QFont font = option.font;
    font.setPointSize ( option.font.pointSize() + 10 );
    painter-&gt;setFont ( font );
    // adjust text to after image
    QRect textrect = option.rect;
    textrect.setLeft ( textrect.left() + mysize.width() );
    painter-&gt;drawText ( textrect , Qt::AlignLeft | Qt::AlignVCenter, thetext );
    painter-&gt;restore();
} else {
    QStyledItemDelegate::paint ( painter, option, index );
}
</code></pre>
<p dir="auto">}</p>
<p dir="auto">QSize TestDelegate::sizeHint ( const QStyleOptionViewItem&amp; option, const QModelIndex&amp; index ) const<br />
{<br />
QSize result = QStyledItemDelegate::sizeHint ( option, index );<br />
result.setHeight ( result.height() * 2 );<br />
return result;<br />
}</p>
</blockquote>
<p dir="auto">Thank you. This helps. I appreciate your help.</p>
]]></description><link>https://forum.qt.io/post/283504</link><guid isPermaLink="true">https://forum.qt.io/post/283504</guid><dc:creator><![CDATA[dheerendra]]></dc:creator><pubDate>Thu, 23 Jul 2015 13:21:11 GMT</pubDate></item><item><title><![CDATA[Reply to QListView : Increasing the cell width and height on Thu, 23 Jul 2015 12:45:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dheerendra">@<bdi>dheerendra</bdi></a><br />
Hi<br />
You do not need to force it to redraw as it will when you move to it or click it.</p>
<p dir="auto">You can try this code for test<br />
it gets you this<br />
<a href="http://postimg.org/image/llsmepjhj/" target="_blank" rel="noopener noreferrer nofollow ugc">http://postimg.org/image/llsmepjhj/</a><br />
(update: drawn center)<br />
Note: the icon can only scale to how large it really is. (it seems)<br />
So a 60x60 image  will max give you 60x60. So if your icon is still small when row is selected, image/icon need to be bigger.<br />
The icon in the sample are inserted with setIcon for the listviewitem. Not sure how you put icons in.</p>
<p dir="auto">I suspect one can do it smarter using  style-&gt;drawControl  and change stuff in option but never really did dig into that.</p>
<pre><code>void TestDelegate::paint ( QPainter *painter, const QStyleOptionViewItem&amp; option, const QModelIndex&amp; index ) const
{

    QStyle* style = option.widget ? option.widget-&gt;style() : QApplication::style();
    QRect rect = option.rect;

    QString thetext = index.model()-&gt;data ( index.model()-&gt;index ( index.row(), 0 ) ).toString();

    if ( option.state &amp; QStyle::State_Selected ) {
        painter-&gt;save();
        // draw selection rext
        style-&gt;drawControl ( QStyle::CE_ItemViewItem, &amp;option, painter, option.widget );
        // get icon and scale it
        QIcon icon = qvariant_cast&lt;QIcon&gt; ( index.model()-&gt;data ( index, Qt::DecorationRole ) );
        //scale it . note must be big enough or you get a smaller
        QSize mysize = option.decorationSize;
        mysize.scale ( mysize.width() + 10, mysize.width() + 10, Qt::KeepAspectRatio );
        QPixmap iconPixmap = icon.pixmap ( mysize );
        //draw icon
        painter-&gt;drawPixmap (  option.rect.x() , option.rect.center().y() - mysize.height()/2 , iconPixmap  );        
        // Change font
        QFont font = option.font;
        font.setPointSize ( option.font.pointSize() + 10 );
        painter-&gt;setFont ( font );
        // adjust text to after image
        QRect textrect = option.rect;
        textrect.setLeft ( textrect.left() + mysize.width() );
        painter-&gt;drawText ( textrect , Qt::AlignLeft | Qt::AlignVCenter, thetext );
        painter-&gt;restore();
    } else {
        QStyledItemDelegate::paint ( painter, option, index );
    }

}

QSize TestDelegate::sizeHint ( const QStyleOptionViewItem&amp; option, const QModelIndex&amp; index ) const
{
    QSize result = QStyledItemDelegate::sizeHint ( option, index );
    result.setHeight ( result.height() * 2 ); 
    return result;
}
</code></pre>
]]></description><link>https://forum.qt.io/post/283497</link><guid isPermaLink="true">https://forum.qt.io/post/283497</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Thu, 23 Jul 2015 12:45:07 GMT</pubDate></item><item><title><![CDATA[Reply to QListView : Increasing the cell width and height on Thu, 23 Jul 2015 12:07:01 GMT]]></title><description><![CDATA[<p dir="auto">Thank you. Yes delegate is the options. How do you force the redraw when the particular row is selected ? I would like to increase the font and icon size only for the row selected.  Other rows(non-selected) rows should remain as is. When the new row is selected, previous selected row should be unselected as well.</p>
]]></description><link>https://forum.qt.io/post/283493</link><guid isPermaLink="true">https://forum.qt.io/post/283493</guid><dc:creator><![CDATA[dheerendra]]></dc:creator><pubDate>Thu, 23 Jul 2015 12:07:01 GMT</pubDate></item><item><title><![CDATA[Reply to QListView : Increasing the cell width and height on Thu, 23 Jul 2015 11:23:08 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
I had no luck changing the font size using a style sheet so I ended up<br />
making a delegate<br />
You can then draw the selected row your self using bigger font and icon.</p>
<p dir="auto">class TestDelegate : public QStyledItemDelegate<br />
{<br />
public:<br />
TestDelegate(QObject* parent = 0);</p>
<p dir="auto">protected:<br />
virtual void paint(QPainter *painter, const QStyleOptionViewItem &amp;option, const QModelIndex &amp;index) const;<br />
QSize sizeHint ( const QStyleOptionViewItem&amp; option, const QModelIndex&amp; index ) const;</p>
<p dir="auto">};</p>
]]></description><link>https://forum.qt.io/post/283486</link><guid isPermaLink="true">https://forum.qt.io/post/283486</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Thu, 23 Jul 2015 11:23:08 GMT</pubDate></item></channel></rss>