Re: How to accelerate the loop speed ?
Hi ,all:
I am working on a small program .This program is to show info on a QTableWidget , it may have thousand rows , but the main time waste section is a loop , code like below :
Code:
int i=0;
vector<Case>::iterator it = tmp.begin();
for(;it!=tmp.end();it++, i++)
{
table->insertRow(i);
}
If I delete the line "table->setCellWidget( i, 0, new QCheckBox(QString("Y/N")));" ,the program will go much more faster ,so that line take the most of the loop run time .What should I do to make the program go faster ?
Added after 18 minutes:
I need some suggestions
Re: How to accelerate the loop speed ?
Don't. Thousands of widgets in a table will not be fast to use, even if you make them faster to create.
QTableWidgetItem supports a check box without the overhead of a widget. Try adapting this:
Code:
for(int i = 0; i < 1000; ++i)
{
item->setCheckState(Qt::Unchecked);
table->setItem(i, 0, item);
}
Re: How to accelerate the loop speed ?
Quote:
Originally Posted by
ChrisW67
Don't. Thousands of widgets in a table will not be fast to use, even if you make them faster to create.
QTableWidgetItem supports a check box without the overhead of a widget. Try adapting this:
Code:
for(int i = 0; i < 1000; ++i)
{
item->setCheckState(Qt::Unchecked);
table->setItem(i, 0, item);
}
I change code like your advice ,but it work the same . Will QTableView have influence ? Do you have any idea ,thanks!
Re: How to accelerate the loop speed ?
It takes literally 15 milliseconds to execute the loop and create the 4000 items in my example.
Post a complete example program that demonstrates the problem.
BTW: You can resize the table widget once to match the item count of the vector rather than increase it row at a time: QTableWidget::setRowCount().
Re: How to accelerate the loop speed ?
I redo it ,it works ! thanks!