[maemo-developers] Position of the icon in QListWidgetItem

From: David Talmage talmage at acm.org
Date: Tue Oct 19 16:15:07 EEST 2010
On 10/19/2010 08:40 AM, Felipe Crochik wrote:
> I haven't tried with a list item but with buttons you can reposition the
> image using just style sheets. Be aware that you (can) have two images: the
> ...
> I am sure you found this already but:
> http://doc.trolltech.com/4.6/stylesheet-examples.html#customizing-qlistview

Thanks for the example and the URL.  I had read that page already. 
What's there doesn't tell me enough about QListView and its style sheet 
items.

I found a solution overnight.  While reading about models and delegates 
in the Qt book, I took a guess that the item index of the icon is 
strictly less than the item index of the text.  With that and a hint I 
found elsewhere, I tried setting the QListWidget's layout direction to 
Qt::RightToLeft.  That fixed my ordering problem.

To make the text flush left, I set each QListWidgetItem's text alignment 
to Qt::AlignLeft|Qt::AlignVCenter|Qt::AlignAbsolute.  The 
Qt::AlignAbsolute is the key.  According to the online documentation, 
when the layout direction is Qt:RightToLeft, the meanings of 
Qt::AlignLeft and Qt::AlignRight are reversed.  Qt::AlignAbsolute 
restores them to their default meanings, the ones they have when layout 
direction is Qt::LeftToRight.

More information about the maemo-developers mailing list