开发者

Font size QComboBox items?

Say I fill QComboBox with a number on each line. And lines are very cl开发者_JAVA技巧ose vertically. How can I control vertical the distance?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜