QFontComboBox custom item height
-
Hello,
I'd like to customize QFontComboBox to have bigger item height but somehow the formatting gets lost in the process.
Default:
Custom style:
My code:
class DropDownItemDelegate : public QStyledItemDelegate { public: using QStyledItemDelegate::QStyledItemDelegate; QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override { QSize s = QStyledItemDelegate::sizeHint(option, index); s.setHeight(40); return s; } }; ui->fontComboBox->view()->setItemDelegate(new DropDownItemDelegate(ui->fontComboBox)); ui->fontComboBox->setEditable(false);
Environment: Win 10, Qt5.15.2
Any tips?
Thanks a lot!
-
Hello,
I'd like to customize QFontComboBox to have bigger item height but somehow the formatting gets lost in the process.
Default:
Custom style:
My code:
class DropDownItemDelegate : public QStyledItemDelegate { public: using QStyledItemDelegate::QStyledItemDelegate; QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override { QSize s = QStyledItemDelegate::sizeHint(option, index); s.setHeight(40); return s; } }; ui->fontComboBox->view()->setItemDelegate(new DropDownItemDelegate(ui->fontComboBox)); ui->fontComboBox->setEditable(false);
Environment: Win 10, Qt5.15.2
Any tips?
Thanks a lot!
@wazzdaman said in QFontComboBox custom item height:
QFontComboBox
QFontComboBox use a dedicated item delegate internally, called
QFontFamilyDelegate
. So by setting a new delegate you are breaking the visual from the original delegate. Unfortunately the classQFontFamilyDelegate
cannot be included as it is defined in the cpp of QFontComboBox. You could probably copy and update it according to your needs but instead of that, I think there is a much simpler solution using style sheet, which seems to work according to your needs. Of course you may need to play a bit with the values for having the result you want.ui->fontComboBox->setFixedHeight(40) ui->fontComboBox->setStyleSheet("QFontComboBox { font-size: 25px }")
-
@wazzdaman said in QFontComboBox custom item height:
QFontComboBox
QFontComboBox use a dedicated item delegate internally, called
QFontFamilyDelegate
. So by setting a new delegate you are breaking the visual from the original delegate. Unfortunately the classQFontFamilyDelegate
cannot be included as it is defined in the cpp of QFontComboBox. You could probably copy and update it according to your needs but instead of that, I think there is a much simpler solution using style sheet, which seems to work according to your needs. Of course you may need to play a bit with the values for having the result you want.ui->fontComboBox->setFixedHeight(40) ui->fontComboBox->setStyleSheet("QFontComboBox { font-size: 25px }")
-
@wazzdaman said in QFontComboBox custom item height:
QFontComboBox
QFontComboBox use a dedicated item delegate internally, called
QFontFamilyDelegate
. So by setting a new delegate you are breaking the visual from the original delegate. Unfortunately the classQFontFamilyDelegate
cannot be included as it is defined in the cpp of QFontComboBox. You could probably copy and update it according to your needs but instead of that, I think there is a much simpler solution using style sheet, which seems to work according to your needs. Of course you may need to play a bit with the values for having the result you want.ui->fontComboBox->setFixedHeight(40) ui->fontComboBox->setStyleSheet("QFontComboBox { font-size: 25px }")