0

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);
Ufx
  • 2,595
  • 12
  • 44
  • 83

1 Answers1

0

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.

Jablonski
  • 18,083
  • 2
  • 46
  • 47
  • I don't want to make table not editable. I want to finish enter new value to editing cell at that moment like I pressed enter key. – Ufx Sep 25 '14 at 15:49
  • @Ufx Sorry, but I understood, see my edit, I test it, works normal. – Jablonski Sep 25 '14 at 15:57
  • @Ufx it works, but setRowCount in your case delete a few or one last row/rows, current cell loses focus and your enter pressing catch tableWidget, not a cell. – Jablonski Sep 25 '14 at 17:10