Persistens selection in Tableview



  • Hi.
    I wanted to ask to for a general suggestion.
    I have a tablemodel, containing a set of constant data. I use a delegate to represent this data in a tableview in a way that to that data to each cell is addet a countdown, showing how much is left, and a progressbar.
    Currently i use

     void emitFakeResetModelSignal()
    { 
    beginResetModel(); 
    endResetModel(); 
    };
    

    connected to a timer to fake that data is changed, so the countdowns are updatet every second, although the data itself isnt changed, i just calculate additional information "on demand", which is adressed by tablemodels data() function. I hope i explained it understandable)))
    Now i want to be able to select rows in tableview and then delete or modify the selected entrys in my model. But since the view updates every second the selection holds only for a second. What is a good approach to make a persistens selection here?


  • Lifetime Qt Champion

    Hi,

    Rather that triggering a model reset, why not just emit dataChanged for the index in questions ?



  • I need the view to be constantly uptodate. So all the cells have to be updated every second or so.


  • Lifetime Qt Champion

    Then emit dataChanged for the whole table.



  • Great, thanks))



  • I have to reopen the thread, couse the problem is on the same subject.
    I have now addet some delegates to my table. I use QCombobox to allow some values to be changed when i want to edit a cell. Problem is, when i open the editor, the table keeps updating every second and each update the combobox gets additional items. Say i offer 3 entry to chose from, ent1, ent2, ent3. So when i keep editor open every second its becomes ent1, ent2, ent3, ent1, ent2, ent3, .... and so on. Do you have some suggestion?

    I solved it now with checking

    if(pQComboBox->count() == 0){//fill combobox}
    

    every time setEditorData is called, but i stil wonder why this happens at all.



  • in the delegate you could call blockSignals(true) in the first line of createEditor() and blockSignals(false) in the first line of editorEvent()

    I don't like it tbh but nor do I like changing the entire model every second for that matter


Log in to reply
 

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