Say I fill QComboBox with a number on each line. And lines are very close vertically. How can I control vertical the distance?
+3
A:
If you just want to change the row height (instead of changing font size) create a new delegate class:
class RowHeightDelegate : public QItemDelegate
{
Q_OBJECT
public:
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
return QSize(1, 40); // the row height is now 40
}
};
And set it to your combobox:
ui->comboBox->setItemDelegate(new RowHeightDelegate());
Edit:
The example above shows how to change row height of the dropdown list. Font size is not changed. If you want to change the font size of the whole combobox (dropdown list included), create a new font with a desired size and set it to the combobox:
QFont font;
font.setPointSize(font.pointSize() + 10);
ui->comboBox->setFont(font);
Or use Qt Designer or Qt Creator to change the font size.
Roku
2010-09-05 11:52:07
Wow...!!! Why so hard? Is this the only way?
Narek
2010-09-05 13:06:02
Is it obligatory to inherit from QItemDelegate to do this simple opertion?
Narek
2010-09-06 17:26:27
Well, it's not *that* hard. My answer contains all the code you need, so it's basically two copy/paste operations :) The easier way is to change the font size of the combobox. That doesn't require writing new code, you can do that using Qt Designer or Qt Creator.
Roku
2010-09-06 17:34:21