<?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[Stylesheets and sizeFromContents]]></title><description><![CDATA[<p dir="auto">I am trying to get a better understanding of the behavior I describe below.</p>
<p dir="auto">I sub-classed QWidget to create a custom widget. For the sake of this question assume all that I did was add a label.</p>
<pre><code>class MyWidget : public QWidget
{
    Q_OBJECT
    
    public:
        MyWidget();
        ~MyWidget();
    private:
        QLabel myLabel;
}

MyWidget::MyWidget(QWidget *parent = 0) :
 Qwidget(parent),
myLabel(new QLabel("",this)
{
}
</code></pre>
<p dir="auto">....</p>
<p dir="auto">I have stylesheet loaded into the application that specifies the minimum and maxiume size of MyWidget and the QLabel.</p>
<p dir="auto">Example:</p>
<p dir="auto">MyWidget,<br />
MyWidget QLabel {<br />
min-height: 65;<br />
max-height: 65:<br />
min-width: 200;<br />
max-width: 200;<br />
}</p>
<p dir="auto">I am trying to draw this inside a listview with a custom delegate but the sizeHint function that I wrote does not behave as I would expect.</p>
<pre><code>QSize MyItemDelegate::sizeHint(const QStyleOptionViewItem &amp;option,
               const QModelIndex &amp;index) const
{
    qDebug() &lt;&lt; "sizehint" &lt;&lt; endl;
    if(index.data().canConvert&lt;MyModelItem&gt;())
    {
        MyModelItem item = qvariant_cast&lt;MyModelItem&gt;(index.data());
        qDebug() &lt;&lt; QApplication::style()-&gt;sizeFromContents(QStyle::CT_ItemViewItem, &amp;option, QSize(),  item.getItem()) &lt;&lt; endl
        
        return style-&gt;sizeFromContents(QStyle::CT_ItemViewItem, &amp;option, QSize(),  item.getItem());
    }
    else
    {
        
        qDebug() &lt;&lt; "Delegate...something broken" &lt;&lt; QStyledItemDelegate::sizeHint( option, index) &lt;&lt; endl;
        return QStyledItemDelegate::sizeHint( option, index);
    }

}
</code></pre>
<p dir="auto">MyModelItem is just structure that has pointer to a MyWidget object.</p>
<p dir="auto">This returns a QSize of 0,37. I am trying to figure out why it is not returning the size that I specified in the stylesheet.</p>
]]></description><link>https://forum.qt.io/topic/65583/stylesheets-and-sizefromcontents</link><generator>RSS for Node</generator><lastBuildDate>Sat, 23 May 2026 21:48:26 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/65583.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 30 Mar 2016 16:14:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Stylesheets and sizeFromContents on Sat, 09 Apr 2016 03:16:36 GMT]]></title><description><![CDATA[<p dir="auto">I'm not sure if this is going to fix your problem, but I think things like min-width, max-width, etc are supposed to end with px such as 65px; and 200px;. Also, you might want to post this in the General Desktop category. You posted this in Language Bindings which gets a lot less views than General Desktop. But you aren't using PyQt, PySide, etc.</p>
]]></description><link>https://forum.qt.io/post/321575</link><guid isPermaLink="true">https://forum.qt.io/post/321575</guid><dc:creator><![CDATA[elveatles]]></dc:creator><pubDate>Sat, 09 Apr 2016 03:16:36 GMT</pubDate></item></channel></rss>