I try to make a own widget for block scanning like a defrag software. I have now a problem with limitation of widgets in QT.
My current approach is:
r = 200 / c = 83
void QScanBoard::setupLayout()
{
this->setAttribute(Qt::WA_LayoutUsesWidgetRect);
this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
gridTable = new QGridLayout;
gridTable->setSpacing(0);
gridTable->setMargin(0);
gridTable->setContentsMargins(0, 0, 0, 0);
gridTable->setSizeConstraint(QLayout::SetFixedSize);
this->setLayout(gridTable);
}
void QScanBoard::createTiles()
{
for (unsigned int r = 0; r < m_numRows; ++r)
{
m_tiles += QList<QScanTile*>{};
for (unsigned int c = 0; c < m_numCols; ++c)
{
// add a new tile to the row
m_tiles[r] += new QScanTile({ r, c }, this);
gridTable->addWidget(m_tiles[r][c], r, c);
}
}
m_tiles[0][0]->setDown(true);
}
QScanTitle is a QPushButton or also a QLabel as sample. I use a QGridLayout to place this widgets on the dialog (widget).
If I use now 200/83 it is fast enough. If I try to set 2000/83 the software will hang. This means with 166000 widgets are too much. But sometimes I need much more.
Any idea how to manage this? Because a widget can only have one parent I cannot add one QPushButton multiple times, I need to create it for each QGridLayout cell a new one.
Can I set a QGridLayout without any widget inside the cells? Just a Background color?
QWidget
s is probably not the way to go. You should probably look atQGraphicsView
/QGraphicsScene
instead. – G.M.QWidget
is a fairly large thing in terms of the resources it uses. As such I suspect any application that has tens of thousands of them (or more) active/visible at any given time will be very resource hungry and sluggish. – G.M.