[Qt-interest] changing style of a QListViewItem

Andre Somers andre at familiesomers.nl
Wed May 26 10:32:05 CEST 2010


On 26-5-2010 10:21, Mandeep Sandhu wrote:
> On Wed, May 26, 2010 at 1:43 PM, Andre Somers<andre at familiesomers.nl>  wrote:
>    
>> On 26-5-2010 9:51, Nishant Sharma wrote:
>>      
>>> Hi,
>>> On double click of a QListViewItem, I want to make that item in bold
>>> and underline.
>>> Can anyone please let me know how to do that ?
>>>
>>>
>>>        
>> If you want to do more advanced things, you have to resort to a
>> delegate, but in this case, you don't need it.
>>      
> How will setting a role change the appearance of the selected text?
> Wouldn't  a custom delegate be needed anyway?
>
> IMHO, bold and underlined is just a different way of showing the
> "selected" state, so that should be the job of a delegate. CMIIW.
>    

If the OP wanted to display the selected state, you are right. You need 
a delegate (or a different style). But double clicking isn't changing 
the selected state, in my book. However, I may have misunderstood.

You can change the font by using QAbstractItemModel::data and returning 
something sensible for the Qt::FontRole. You can als modify colors 
(foreground and background) and alignment this way, along with some 
other properties.

André

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100526/dd3248ee/attachment.html 


More information about the Qt-interest-old mailing list