Different editor widgets in QStyledItemDelegate



  • I'm attempting to create a "property editor" type widget analogous to the one in the Qt Designer.

    The issue I am facing is how to handle the creation of different editor widgets in the "value" column, depending on the expected input type. I.e. QDoubleSpinBox for decimal input, QComboBox for selection from a list, etc.

    I began trying to implement this capability through subclassing QStyledItemDelegate (overriding QStyledItemDelegate.createEditor()) and setting the delegate in my QTreeView. I can find plenty of examples for this procedure when setting the same widget for an entire column. However, I cannot seem to extrapolate from these examples to set widgets in the "value" column depending on the data in the "property column".

    I'll try to graphically show below what I want.

    Hopefully someone can point me in the right direction, thanks.


  • Lifetime Qt Champion

    Hi,

    In the createEditor function you should query the type of what you are going to show and based on that return the corresponding widget.

    Hope it helps


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.