ListWidgetItem and Icon



  • I have a list widget to which i add listWidgetItems to it.The list widget item has text on the left and an icon on the right.When there is no icon the text has some spacing between the margin of list widget but when i add icon to it this spacing is gone.I set the text alignment as Qt::AlignLeft | Qt::AlignVCenter | Qt::AlignAbsolute .
    Any suggestions?



  • Hi DivyaPrakash.
    Welcome on Qt Dev forum

    First of all you should clear your question ..What you want to achieve?

    Second thing is as you mentioned that text on left and icon on right is wrong it happens to be in reverse order(by default).

    if you want spacing b/w icon and text then you can add some space character(s)
    before text.

    Hope this would help.
    [Edit by IamSumit ]



  • Well, the order would depend on the settings of Qt. It can run in right-to-left mode when needed for some languages.



  • @IamSummit ...I want a consistent behavior meaning even when there is a icon, still there should be some spacing between the list widget and list widget item.
    http://postimg.org/image/rffa27j1z/

    See the screen shot the text starting with B does not have a icon to it.
    But the text starting with A has a icon to it,but for some reason after adding the icon the text gets shifted towards left.

    I made it reverse intentionally.



  • @IamSummit ...I want a consistent behavior meaning even when there is a icon, still there should be some spacing between the list widget and list widget item.

    I made it reverse intentionally.Also this strange behavior is also present on Mac



  • I see three options:

    • Put the icon in a column of its own
    • Always put an icon, even if it is just a 100% transparent png of the same size as your other icons
    • Implement your own delegate for the rendering

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.