Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QTableView doesn't respond to dataChanged when not focused

Tags:

c++

qt

model-view

I have a QTableView that's connected to a QAbstractTableModel subclass. I'm editing the data owned by the model in response to user input in a different control (not the QTableView), and then I'm calling a method on the model that emits the dataChanged event:

void CharacterModel::characterChanged(int idx)
{
    emit dataChanged(index(idx, 0), index(idx, (int)kNumColumns));
}

This works, as long as the QTableView is focused. As soon as it's not, it no longer shows the updated data. If I focus it again, it updates immediately. For example, I modified my code that's calling the above method to call setFocus() on the table view right afterwards, and everything is fine - except that my editing control loses focus every time I do anything. Not OK. I have several editing controls, including spin boxes; if I click on the spin box arrow, the FIRST update is displayed (because the table view is still focused), but then the spin box gets focused and all subsequent changes don't get displayed.

Anybody have any idea what's going on? This seems to be extremely well-defined behavior, but I can't find any reference to it anywhere.

Thanks, Aaron

like image 956
phrixus Avatar asked Nov 01 '25 12:11

phrixus


1 Answers

I think I've solved this. Turns out the solution is to call tableView->viewport()->repaint() after the dataChanged event fires. Calling tableView->repaint() doesn't do it.

like image 141
phrixus Avatar answered Nov 04 '25 01:11

phrixus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!