0
votes

I need to finish edit QTableWidget when some event happend.

MyWindow::onSomeEvent
{
  // Finish ui->table editing
  //...
}

How can I do this?


The event is a spinbox editing. When it happend rows count becomes equled its value.

I tried to send enter key press event. But when editing item in the last row and new rows count is less then current it does not work.

QKeyEvent *ev = new  QKeyEvent(QEvent::KeyRelease,
                               Qt::Key_Return,
                               Qt::NoModifier);

QApplication::sendEvent(ui->table, ev);
ui->table->setRowCount(value);
QApplication::sendEvent(ui->table, ev);
1

1 Answers

0
votes

Try this:

MyWindow::onSomeEvent()
{
    QKeyEvent *ev = new  QKeyEvent(QEvent::KeyRelease,Qt::Key_Return,Qt::NoModifier);
    QApplication::sendEvent(ui->tableWidget,ev);
}

You just emulate Enter pressing when something happens.