Qt World Summit: Register Today!

Editor created by QStyledItemDelegate is not inheriting container width

  • I'm currently working on a program that has an editor component built on a QListView that uses a QStyledItemDelegate to draw the item in the list. I'm using createEditor to create another widget for editing the selected list item's contents but, no matter what widget I use, it does not inherit the full width of the list cell.

    I've looked at all the layout and geometry settings to no avail.
    Below is an image that demonstrates the issue:
    0_1560855451433_Screenshot from 2019-06-18 11-56-26.png

    As you can see, the editor widget is offset to the left by quite a bit. My understanding was that the editor is just an overlay and should inherit the region/rect that the delegate has.

    Any insight would be much appreciated.

  • I eventually managed to fix this by implementing updateEditorGeometry and calling editor->setGeometry(option.rect);. I should have looked into base class member functions sooner!