Question

I have a QTableWidget table with more than 2000 rows. When i add QToolButton "Remove" in each row, it become a little bit slow). Why table become slow, buttons ui or signal mapper? How can i speed up my table, maybe replace buttons with something else or connect signals in other way?


My code for buttons:

    // mapper for remove buttons
    QSignalMapper* signalMapper = new QSignalMapper(this);
    connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(RemoveString(int)), Qt::UniqueConnection);

than for each row:

    //remove button
    QToolButton* remove_button = new QToolButton(this);
    remove_button->setText("Remove");
    signalMapper->setMapping(remove_button, index);
    connect(remove_button, SIGNAL(clicked()), signalMapper, SLOT(map()), Qt::UniqueConnection);
    ui->locale_table->setCellWidget(index, 3, remove_button);

enter image description here

Was it helpful?

Solution

As vahancho said you will want an item delegate. Item delegates simply display the data and information in a certain way. It mainly paints the item to look like what you want, so it doesn't necessarily create a whole widget. You will probably want to use a styled item delegate. http://qtadventures.wordpress.com/2012/02/04/adding-button-to-qviewtable/ This should have all of the information you need.

You set the item delegate to the widget with the QTableWidget methods setItemDelegate, setItemDelegateForColumn, setItemDelegateForRow.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top