Unsolved pixmap and text alignment in IconView
-
I have used QListView to show thumbnails. And set the stylesheet to adjust icons.
QListView* iconView=new QListView; iconView->setViewMode(QListView::IconMode); iconView->setUniformItemSizes(true); iconView->setStyleSheet("QListView::item:deselected { border: 1px solid black; border-radius: 6px; color: black;} QListView::item:selected {background: white; border: 4px solid blue;}");
As you can see, vertically the pixmap aligns to top of border and the text aligns to middle of rest space. You can see it clearly in the second icon. But I want the other way around.
Can anyone tell me how I can change the alignment of pixmap and text so that first, the text is positioned to the bottom of border, and then the pixmap algins at the middle of the rest space? -
@samdol You can adjust the text using stylesheet as follows:
"QListView::text{" "bottom: -4px;" //negative values "}"
-
@p3c0
I tried but the pixmap takes the top part of icon and the text still aligned middle of the rest of space. -
@samdol AFAIK these are the only ways to adjust the icon and text in listview items using stylesheets.
QListView::text QListView::icon
You can try setting
padding-left, right, bottom and top
or justleft, right, top and bottom
for adjusting their positions.
More info here:
http://doc.qt.io/qt-5/stylesheet-reference.htmlBut in the end the best way is to create a custom delegate using QStyledItemDelegate.
-
@p3c0
I have tried
QListView::text{bottom: -4px;}
But it lowers down the text -4px from the center line of the rest space after icon. Thus if icons have different heights, meaning different reft over space after the icons, texts after them are not aligned horizontally. Some text is higher than other texts. I would like to have all the texts to be aligned at the bottom of the border. -
@samdol Well then you are only left with using QStyledItemDelegate.
-
Hi Sam,
According to the docs,
iconView->setUniformItemSizes(true);
may only be set if items are indeed the same size.
No idea if it will work, but try setting the gridSize instead...