سؤال

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?

هل كانت مفيدة؟

المحلول

Try this answer.

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top