Hi,

I'm using a QListWidget to display some icons vertically. Here is my code:

Qt Code:
  1. contentsWidget = new QListWidget;
  2. contentsWidget->setViewMode(QListView::IconMode);
  3. contentsWidget->setMovement(QListView::Static);
  4. contentsWidget->setFlow(QListView::TopToBottom);
  5. contentsWidget->setIconSize(QSize(96, 65));
  6. contentsWidget->setMaximumWidth(150);
  7. contentsWidget->setSpacing(12);
To copy to clipboard, switch view to plain text mode 

My problem is that the icons appears on the left side of the QListWidget and I would like them to be aligned to the center.

At the beginning I naturally thought about changing the alignment in the QListWidget layout:

Qt Code:
  1. contentsWidget->layout()->setAlignment(Qt::AlignHCenter);
To copy to clipboard, switch view to plain text mode 

And the code compiled. But the application crashed when I ran it...

I have looked probably everywhere in Qt's documentation but I still haven't found what I'm looking for. Does somebody know how to set the alignment properly ?