Layout modification in QListWidget
Hi,
I'm using a QListWidget to display some icons vertically. Here is my code:
Code:
contentsWidget
->setViewMode
(QListView::IconMode);
contentsWidget
->setMovement
(QListView::Static);
contentsWidget
->setFlow
(QListView::TopToBottom);
contentsWidget
->setIconSize
(QSize(96,
65));
contentsWidget->setMaximumWidth(150);
contentsWidget->setSpacing(12);
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:
Code:
contentsWidget->layout()->setAlignment(Qt::AlignHCenter);
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 ?
Re: Layout modification in QListWidget
Hi guys,
I'm still struggling with this issue. Does anyone have an idea about how to deal with this problem ?
Re: Layout modification in QListWidget
Quote:
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.
You might be able to do that only with the delegates. Changing layout wont help.
Have a look at QStyledItemDelegate and QItemDelegate.
What you will need to do is, set the position of icon drawing(called decoration ) in the options and then call the delegates function to draw the icon.