Question

Say I fill QComboBox with a number on each line. And lines are very close vertically. How can I control vertical the distance?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top