PDA

View Full Version : Text inside QListWidgetItem moving to the left when QIcon is added from the right.



Sadaab
21st March 2016, 07:34
Hello,
I am working on a application for both Mac and Windows.
I am using QListwidget to list down few things and I add QListWidgetItem to it.
Each QListWidgetItem has some text and based on somoe conditions I add a warning Icon to it from the right side to indicate to the user that something has gone wrong.

Now the problem is only on MAC, whenever I add this Icon from the right side the text moves slightly to the left which doesn't look good. There is enough space for the Icon to be there but still it pushes the text to the left.

The text alignment is set using:
setTextAlignment( Qt::AlignLeft | Qt::AlignVCenter | Qt::AlignAbsolute );

Icon is added and removed using this code:

void ChangeState( bool inState )
{
QIcon icon;
if( inState )
{
QPixmap pixmap("Info_icon.png");
icon.addPixmap( pixmap, QIcon::Normal, QIcon::On );
}
else
{
QPixmap pixmap;
icon.addPixmap( pixmap, QIcon::Normal, QIcon::Off );
}
setIcon( icon );
}

Does anyone have any solution to stop the movement of Text to the left when ChangeState( true ) is called.

Please the attachment to get more idea.