Thanks man figured it out if anyone else wants to know here is my code:
QString selectedFoods;
To copy to clipboard, switch view to plain text mode
when I press the button:
if(textEdit->isEmpty()){
selectedFoods.append(selectedItems);
} else {
selectedFoods.append(", "+selectedItems);
}
if(textEdit->isEmpty()){
selectedFoods.append(selectedItems);
} else {
selectedFoods.append(", "+selectedItems);
}
To copy to clipboard, switch view to plain text mode
on the remove button:
selectedFoods.remove(selectedItem);
textEdit->setText(selectedFoods);
selectedFoods.remove(selectedItem);
textEdit->setText(selectedFoods);
To copy to clipboard, switch view to plain text mode
there is one slight problem though but I'm sure I can figure a way to solve it unless anyone has any suggestions.
it removes all the strings with those characters for example if I have a string of "appleapple" and i remove "apple" it will make the first string "" instead of just "apple" probably a way to remove the first string behind the cursor and another bug is with the ", " prob need to do another if statement like
if(selectedFoods.size()<1){
selectedFoods.remove(", "+selectedItems);
}
if(selectedFoods.size()<1){
selectedFoods.remove(", "+selectedItems);
}
To copy to clipboard, switch view to plain text mode
or something similar to that.
actually to fix that second bug with the ", " I can instead of putting that in the string just put it in the button press code like
textEdit.setText(", "+selectedFoods)
textEdit.setText(", "+selectedFoods)
To copy to clipboard, switch view to plain text mode
Added after 1 15 minutes:
Edit fixed all my problems here is the code to remove just 1 item =]
int index = selectedFoods.indexOf(selectedItem);
int length = selectedItem.length();
if(selectedItem.length() == selectedFoods.length() && index == 0){
selectedFoods.replace(index,length,"");
} else if(selectedItem.length() < selectedFoods.length() && index == 0){
selectedFoods.replace(index,length+2,"");
} else if(selectedItem.length() < selectedFoods.length() && index != 0){
selectedFoods.replace(index-2,length+2,"");
}
textEdit->setText(selectedFoods);
int index = selectedFoods.indexOf(selectedItem);
int length = selectedItem.length();
if(selectedItem.length() == selectedFoods.length() && index == 0){
selectedFoods.replace(index,length,"");
} else if(selectedItem.length() < selectedFoods.length() && index == 0){
selectedFoods.replace(index,length+2,"");
} else if(selectedItem.length() < selectedFoods.length() && index != 0){
selectedFoods.replace(index-2,length+2,"");
}
textEdit->setText(selectedFoods);
To copy to clipboard, switch view to plain text mode
Thanks for all the help
Bookmarks