0
votes

I am taking an existing UI component that we have based on QTableWidget and placing two of them inside QTabWidget pages. I want to allow the user to enter data into the table in the first tab and then when they press a button to move to the second tab and have the first cell in edit mode.

I am using the editItem method of QTableWidget to edit a given QTableWidgetItem. The trouble is that something is occurring to stop the edit (or maybe it never starts in the first place).

If I call editItem a second time then it fails, but if I click on the cell then it will enter the edit mode with the cell highlighted and the cursor blinking. I was just wondering if there is a way to do this programmatically that I may have missed?

One option would be to simulate a tab key press and then shift-tab but I have not been able to do this. I can simulate the tab but if I try to add the shift modifier then it jut produces a normal tab.

This is my tab code that works:

QApplication::postEvent(tableWidget, new QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier));

This is my shift-tab code that doesn't work:

QApplication::postEvent(tableWidget, new QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier));

Any suggestions would be appreciated.

1

1 Answers

0
votes

It looks like shift-tab is actually reported as Qt::Key_Backtab rather than Qt::Key_Tab with the shift modifier as I had expected...

I think this will do the job for us but would welcome any better solutions.