0

I’ve created a custom model, view (tree) and delegate and everything seems to be working OK with one minor issue. Some of the cells of the tree are combo boxes. The combo boxes work as expected when selected by the user (custom createEditor, setEditorData and setModelData delegate methods). The issue I have is the down arrow is only displayed when the cell is selected. I would like the down arrow to be displayed all the time.

I’m not sure which method is control’s the display of the down arrow. Does it come from the model data (maybe the decorationrole) or is it the paint method of the delegate. Note I’m not using any style sheets.

Update:

Found the solution I was after here. Basically ended up with the following in the paint method of my custom delegate.

    QStyleOptionComboBox comboBoxOption;
    comboBoxOption.rect = option.rect;
    comboBoxOption.state = option.state;
    comboBoxOption.state |= QStyle::State_Enabled;
    comboBoxOption.editable = false;
    comboBoxOption.currentText = index.data(Qt::DisplayRole).toString();

    QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &comboBoxOption, painter);
    QApplication::style()->drawControl(QStyle::CE_ComboBoxLabel, &comboBoxOption, painter);

1 Answers1

0

When QTreeItemView show own items. It's use QStyledItemDelegate for show content. When you edit cells, creates real QCombobox widget. So, editing and showing items have different approaches. You should change QStyledItemDelegate::paint logic for see additional decorations when cells just showing (painting). Make children of QStyledItemDelegate and define own paint() method. That will not simple for first time. But that true way to implement "arrow" in cells.

stanislav888
  • 374
  • 2
  • 9