QTableWidget performance / GUI responsivenes



  • Dear friends,

    I am working on an object detection solution:

    1-Thread detection object and make calculation etc. Sending the results , pictures and the live stream video to the main thread GUI through signal / Slot mechanism.

    All working great but after 10 min main thread (GUI ) start to unresponsive.

    We are using QtableWidget to show pictures (150x150 pixel) each row , meta info text(80 char).

    worker thread sending very fast (4-7 pic/sec) signal sometimes.

    After a while 10 min or after 1000 rows gui looks unresponsive.

    What is your experince ? is this a good idea to use qtablewidget or some other solution suggested ?

    thanks..



  • @RahibeMeryem said in QTableWidget performance / GUI responsivenes:

    We are using QtableWidget to show pictures (150x150 pixel) each row

    Are you using setItemWidget? if so, that's your bottleneck. Store the images in the Qt::DecorationRole of the QTableWidget using setData. You can customise the appearance by reimplementing QStyledItemDelegate



  • Below the code that updates the QtableWidget ; data coming from the signal/Slot mechanism (QVariant type . include both QPix and text)

        QTableWidgetItem* item       = new QTableWidgetItem;
        QTableWidgetItem* item_cam   = new QTableWidgetItem;
        QTableWidgetItem* item_dist  = new QTableWidgetItem;
        QTableWidgetItem* item_notes = new QTableWidgetItem;
    
        item->setData(Qt::DecorationRole,metaTable.db_found_obj);
        item_cam->setData(Qt::DecorationRole, (metaTable.live_big_chip).scaledToWidth(150));
    
        item_notes->setText(metaTable.db_obj_notes);
        item_dist->setText(metaTable.db_found_obj_name);
    
        setUpdatesEnabled(false);
    
        ui->tableWidget->horizontalHeader()->AdjustToContents;
        ui->tableWidget->insertRow(0);
    
        ui->tableWidget->setItem(0,0,item);
        ui->tableWidget->setItem(0,1,item_cam);
        ui->tableWidget->setItem(0,2,item_dist);
        ui->tableWidget->setItem(0,3,item_notes);
        row_count++;
    
        setUpdatesEnabled(true);
    
        QWidget::update();
        ui->tabWidget->repaint();
        qApp->processEvents();
    
    

  • Lifetime Qt Champion

    Hi,

    Why are you disabling/enabling the updates every time you add new elements ? Basically you are asking for a full repaint every time you add data.



  • I did it because the tableWidget not updated realtime. The problem table updated with pix but not seen corrctly, when I mouse over it shows the updated pix. This is why I try dissable/enable.

    :)



  • QTableWidget is a convenience class. If you need fast updates it's much better to use a QTableView and write a proper model.
    The update stuff including setUpdatesEnabled(false/true) is not needed at all and adjustToContents() will also slow down everything since it has to ask (nearly) every cell for it's width.
    When you have sorting enabled you should make sure to disable sorting before insertion ( see http://doc.qt.io/qt-5/qtablewidget.html#details )



  • Thanks..

    It getting faster already and now all looks good.

    thx again.


  • Lifetime Qt Champion

    Good !

    Then please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.