PDA

View Full Version : QListView + row height



NoRulez
2nd February 2009, 19:14
Hey @all,

how can I set the row height in a QListView?
With a QTableView i can use setRowHeight() but how i can do it with a QListView?

LG NoRulez

wysota
3rd February 2009, 16:40
Either set the size using the SizeHintRole of the model or provide your own item delegate with reimplemented sizeHint().

deepal_de
4th May 2011, 08:34
Can i set rowsize using Stylesheet of QListWidget??

wysota
4th May 2011, 10:59
Use the ::item sub-control for QListWidget.

monst
12th May 2012, 08:53
Thanks wysota, but it doesn't work for me when I'm trying to customize row height for combo box popup.
Actually stylesheet reference recommends to do it via "QComboBox QAbstractItemView" selector, but
"QComboBox QAbstractItemView::item" doesn't custom anything.

I suggested that ::item subcontrol is available only for concrete QAbstractItemView subclasses, not for
QAbstractItemView itself. I read qt code and found that QComboBox uses QComboBoxListView class which
is a subclass of QListView. So I tried to use "QComboBox QListView::item", but it doesn't work too.

I solved my problem with a help of this class:



class CComboBoxPopupItemDelegate : public QStyledItemDelegate
{
public:
CComboBoxPopupItemDelegate(QObject* parent = 0)
: QStyledItemDelegate(parent)
{
}

QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
{
return QSize(60, 100); //enter your values here
}
}


In client code:



QAbstractItemView* view = comboBox->view();
view->setItemDelegate(new CComboBoxPopupItemDelegate(this))


Alas I coudn't find easier solution.