I have an application which uses QGridLayout, and often can require 200 to 300 rows. We found layout issues (i.e. the widget would not render) when attempting to use that many rows; QGridLayout appears to have a limit of around 100 rows. We never found a way around that issue, so we append a new QGridLayout when the prior one reaches 100 rows. The problem is that the first gridlayout has a header row which is driving the column width. The appended gridlayouts don't have that header row, therefore their column widths do not match those of the first gridlayout.
I tried the following approach to synchronize the column widths:
auto oldGridLayout = qobject_cast<QGridLayout *>(m_gridLayouts.at(static_cast<unsigned>(m_gridLayouts.size() - 2)));
auto newGridLayout = qobject_cast<QGridLayout *>(m_gridLayouts.at(static_cast<unsigned>(m_gridLayouts.size() - 1)));
for (int i = 0; i < oldGridLayout->columnCount(); i++) {
auto oldLayoutItem = oldGridLayout->itemAtPosition(0, i);
auto newLayoutItem = newGridLayout->itemAtPosition(0, i);
newLayoutItem->setGeometry(oldLayoutItem->geometry());
}
auto oldGridLayout = qobject_cast<QGridLayout *>(m_gridLayouts.at(static_cast<unsigned>(m_gridLayouts.size() - 2)));
auto newGridLayout = qobject_cast<QGridLayout *>(m_gridLayouts.at(static_cast<unsigned>(m_gridLayouts.size() - 1)));
for (int i = 0; i < oldGridLayout->columnCount(); i++) {
auto oldLayoutItem = oldGridLayout->itemAtPosition(0, i);
auto newLayoutItem = newGridLayout->itemAtPosition(0, i);
newLayoutItem->setGeometry(oldLayoutItem->geometry());
}
To copy to clipboard, switch view to plain text mode
The above approach did not work. Investigating a bit more, geometry().width() was not giving an accurate value. Perhaps I was queering prior to the widget had enough knowledge about itself (i.e. not fully rendered), but I don't see a different approach since both widgets are rendered in the same event.
The app using these appended gridlayouts is stable and not much will be spent on it for future improvements. I'm hoping to find a solution which won't involve major surgery. Any suggestions appreciated.
Bookmarks