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

QLineEdit/CheckBox/etc with a model for data?



  • Hey

    Uhh this one has been bothering me for a long while. Essentially I'd like to configure my widgets to receive data from and to central location. The main issue I have is that I can have as many widgets as user wants representing given "data" so if one widget is being updated, then all others should as well. I wonder if qt overs anything like that, or has a signals that I can use to build it up ? Or it will be mostly custom job?

    Something like.... QGraphicsScene or QAbstractItemModel. Where any view using the model gets update info to redraw when user does stuff?

    Regards
    Dariusz
    TIA


  • Moderators

    @Dariusz said in QLineEdit/CheckBox/etc with a model for data?:

    Something like.... QGraphicsScene or QAbstractItemModel. Where any view using the model gets update info to redraw when user does stuff?

    you can write a generic wrapper which listens to a QPersistentModelIndex and emits a signal whenever the dataChanged() signal for that index is triggered. If thats the case the wrapper can emit another signal. The target widget then can connect to this signal and update it's value accordingly. Then you can reuse the wrapper implementation for any widget.



  • @raven-worx said in QLineEdit/CheckBox/etc with a model for data?:

    @Dariusz said in QLineEdit/CheckBox/etc with a model for data?:

    Something like.... QGraphicsScene or QAbstractItemModel. Where any view using the model gets update info to redraw when user does stuff?

    you can write a generic wrapper which listens to a QPersistentModelIndex and emits a signal whenever the dataChanged() signal for that index is triggered. If thats the case the wrapper can emit another signal. The target widget then can connect to this signal and update it's value accordingly. Then you can reuse the wrapper implementation for any widget.

    Oh humh, I dont want to connect to the model systems of treeviews/graphicsScenes, I'm looking for a standalone one for qlineedit/checkbox/radio button etc etc. But the more I think of it I think I might need to write my own class for it whh or at least a "signal" "manager".

    Something like

    connect(this,&QLineEdit::textChanged,={widgetSignalManager::lineEditTextChanged(this, dataId,widgetKey, textOld,textNew)})

    connect(widgetSignalManager, &widgetSignalManager::lineEditTextChanged,={if(widget!=this){if(widgetDataId==dataId){setText(textNew)}})

    And then on widgetSignalManager I can emit that to any listening widgets as well as find the member objects that holds the map with the data to update it... hmmmmmmmmmmm o.O

    something like this o.O oh dear.... this is gonna be "fun" ;- )


Log in to reply