Question

I have implemented ComboBoxDelegate. It is derived from QStyledItemDelegate. Paint function is used to show the content of cell when it is not editing node.

void ComboBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
    QStyleOptionComboBox comboBoxOption;
    comboBoxOption.rect = option.rect;
    comboBoxOption.state = QStyle::State_Active | QStyle::State_Enabled;
    comboBoxOption.frame = true;
    comboBoxOption.currentText = index.model()->data(index).toString();
    QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &comboBoxOption, painter);
    QApplication::style()->drawControl(QStyle::CE_ComboBoxLabel, &comboBoxOption, painter);
}

Now I am trying to implement LineEditDelegate. I don't know how to write its paint function. Is there QStyleOptionComboBox like class for QLineEdit? Can you please share your code if anyone have done it?

Was it helpful?

Solution

Try this answer.

It uses QStyle::drawPrimitive with QStyle::PE_PanelLineEdit element.

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