[Qt-interest] Slow? painting of rows in QTableWidget

Andreas Pakulat apaku at gmx.de
Wed Mar 25 23:22:03 CET 2009


On 25.03.09 22:33:51, Sandro Frenzel wrote:
> 
> -------- Original-Nachricht --------
> > Datum: Wed, 25 Mar 2009 20:42:26 +0100
> > Von: Andreas Pakulat <apaku at gmx.de>
> > An: qt-interest at trolltech.com
> > Betreff: Re: [Qt-interest] Slow? painting of rows in QTableWidget
> 
> > On 25.03.09 18:29:36, Sandro Frenzel wrote:
> > > Hello,
> > > 
> > > I experiment with tables in QT4. I create a QTableWidget and insert
> > > 600
> > > new rows. It takes 5 seconds on a 2,5 GHZ Intel Core2Duo to paint all > > rows.
> > > 
> > > My question: Is that normal? Can I accelerate this operation?
> > 
> > Did you profile your app to see where the time is spent? If you add all
> > items in a short loop that should be relatively fast as there's no
> > gui-updates in between. However the tablewidget class might do layout
> > recalculations on each new row, you can help with that by specifying 
> > that
> > your items all have the same height and/or width (there's a setter for
> > that
> > in the QTableView base class).
> > 
> 
> Hm, I have implemented following simple loop:
>  
> void MainWindow::on_pushButton_clicked() {   
> 
> int i = 0;
> while(i<650) {
>    ui->tableWidget->insertRow(i);
>    i++;
> }
> 
> }
> 
> The rows are shown at once, when the loop ist completed (5 seconds). Height and width are set in the designer.  

Can't see anything suspicious there, so you probably need to get a profiler
working on your code.
 
> > Another downside of qtablewidget is that you can't easily add n rows at
> > once, with only one relayouting being done. For that you'd have to use
> > QTableView+Model (not sure wether QStandardItemModel would be of use for
> > that).
> 
> Can you give me a little example? I found nothing about it. I can set the 650 rows in the table-model and show it without waiting?

The change would be that you'd tell the view about the added row once you
actually have all 650 in place in your model. So the tablewidget only needs
to calculate the sizes and posistions (i.e. its internal layout) only one
time, instead of going through the layouting code 650 times. 

That said, this is all just guesswork, without some real profiling data its
hard to give exact advices on what to improve.
 
Andreas

-- 
You worry too much about your job.  Stop it.  You are not paid enough to worry.



More information about the Qt-interest-old mailing list