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