Best approach to setting cells in table widget
-
Given a table widget (pointed to by imageList) whose data is held as QStrings, if I want to update specific columns for a row which I can identify by its content, is this the best approach:
for (int row = 0; row < imageList->rowCount(); ++row) { if (name == imageList->item(row, static_cast<int>(ImageListColumns::File))->text()) { imageList->item(row, static_cast<int>(ImageListColumns::dX))->setText(QLocale::toString(dX, 'f', 2)); imageList->item(row, static_cast<int>(ImageListColumns::dY))->setText(QLocale::toString(dX, 'f', 2)); imageList->item(row, static_cast<int>(ImageListColumns::Angle))->setText(QLocale::toString(angle, 'f', 2)); break; } }
If not how should I handle this?
Thanks
David -
Given a table widget (pointed to by imageList) whose data is held as QStrings, if I want to update specific columns for a row which I can identify by its content, is this the best approach:
for (int row = 0; row < imageList->rowCount(); ++row) { if (name == imageList->item(row, static_cast<int>(ImageListColumns::File))->text()) { imageList->item(row, static_cast<int>(ImageListColumns::dX))->setText(QLocale::toString(dX, 'f', 2)); imageList->item(row, static_cast<int>(ImageListColumns::dY))->setText(QLocale::toString(dX, 'f', 2)); imageList->item(row, static_cast<int>(ImageListColumns::Angle))->setText(QLocale::toString(angle, 'f', 2)); break; } }
If not how should I handle this?
Thanks
David@Perdrix
Code is fine. Not sure what your question is. If you identify the row by comparing the text of one column against what you are looking for that's OK. Then you set each column's item to some text that's OK.If, for example, there were other magical calls, such as "set a whole row of columns to this list of values" then it would be documented, but it isn't.