I like to color all selected cells in a QTablewidget. But this should be done if the user releases the mouse button. At the moment I have the following code in the table's itemSelectionChanged signal:
QList<QTableWidgetItem *> selections = table->selectedItems();
for(int i=0;i<selections.size();i++) {
int row=selections.at(i)->row();
int col=selections.at(i)->column();
newItem
->setBackgroundColor
(QColor("#0000FF"));
table->setItem(row, col, newItem);
}
QList<QTableWidgetItem *> selections = table->selectedItems();
for(int i=0;i<selections.size();i++) {
int row=selections.at(i)->row();
int col=selections.at(i)->column();
QTableWidgetItem *newItem = new QTableWidgetItem();
newItem->setBackgroundColor(QColor("#0000FF"));
table->setItem(row, col, newItem);
}
To copy to clipboard, switch view to plain text mode
The code is working fine so far, but if e.g. the user moves over the rows 0-3 but actually he only wants to select row 0-2 and he moves back to row 2 and releases the mouse button, row 3 is already colored because he moved already over it. I don't want that, in this case only row 0-2 should be colored.
How can I do that?
Thanks for answers!
Bookmarks