Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How can I remove duplicate values from QTableWidget
Hello, I was wondering how I can remove any duplicates from a table in pyside2 as when my program runs there is a refresh button that adds ab values that previously did not exist but when I press the button it also duplicates values that are already there!
So how do I go about stopping this?
has no one come up with a solution?
Erudite Monkey last edited by
I don't know how you're entering data into the widget but if you want to only store distinct items then maybe store the data of the table widget in a python 'set()' or maybe share your refresh function.
Denni 0 Banned last edited by
Yes the basic question should be not "How do I remove duplicates from a table view" but more "How do I stop from putting duplicates into a table view". Keep in mind the latter is actually much easier than the former and is the proper methodology. Duplicates (if not desired) should never be allowed into the table view to begin with. If they are getting there then the onus is on the procedures that are responsible for adding data to the table view and that is where you need to fix your code. There are numerous ways to do this one of which has already been suggested. Still the best way for you would be to post your minimal fully functioning code so we can help you redesign it to work properly.
@Denni-0 oh if the latter is easier do you mind showing me an example please?
Denni 0 Banned last edited by Denni 0
The following is not going to be code just the how to in general:
Update Occurs Get Data from Source Check to See if it is currently in your DataListOrDict If No Then Put Data into DataListOrDict Sort DataListOrDict Purge TableView Reload TableView from Sorted-DataListOrDict May need to do a GUI refresh of some sort
If your data is too complicated then
Put Data into DataDict and DataIndxDict Sort DataIndxDict Purge TableView Using the DataIndxDict Reload TableView from DataDict May need to do a GUI refresh of some sort
I hope that helps (and p.s. ;) < notice wink and smile I am not going to do all your coding for you but nice try )
@Denni-0 oh right okay thanks I will try and see if i can put his in code!