Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Delegate access in view



  • Hi all,

    using model view architecture. Qt 5.9.3

    I want to call a member function in a combobox delegate placed in a particular cell to dynamically change it's contents.

    I don't see any way to access this?? Cannot get a pointer to it..so is this possible? If not WHY not..seems like it should be simple to do...

    I do NOT want to destroy it and re-create it each time it changes, this takes too long..

    Every spread sheet program lets you do something like this..so why is this not documented anywhere I can see...

    Thanks


  • Lifetime Qt Champion

    Hi,

    Where are you getting this data from ?



  • Data comes from a model as an int to set the combobox.

    I managed to do this:
    ComboBoxDelegate *TypeDelegate; // our custom drop box

    // Make sure we are at the selected row in tableview....
    TypeDelegate =(ComboBoxDelegate *)ui->IDC_SLIST->itemDelegateForColumn(1);
    TypeDelegate->SetCmdSet(Sel); // tell drop what list to load

    This seems to work ok, but not sure casting is typesafe or the right way to do it...
    IDC_SLIST is a TableView

    Ken


  • Lifetime Qt Champion

    Hi
    The c cast is not optimal. we have qobject_cast which is safer.

    TypeDelegate =   qobject_cast<ComboBoxDelegate *> ( ui->IDC_SLIST->itemDelegateForColumn(1) );
    if (TypeDelegate ) { // check if cast worked
    TypeDelegate->SetCmdSet(Sel); // tell drop what list to load
    }
    


  • Thanks for that, I will update the code

    Ken


Log in to reply