QTableWidget inserts a new row when Enter key is pressed in a blank cell.
How can I suppress this behavior?
Should I catch the enter-key event using an event filter?
QTableWidget inserts a new row when Enter key is pressed in a blank cell.
How can I suppress this behavior?
Should I catch the enter-key event using an event filter?
Hmmm does it?
That's interesting.
You're sure you're not doing it somehow?
Which Qt version you're using?
Hi, thank you for reply.
I am using Qt 4.8.0 on Linux/X11.
When I select a cell with a mouse click and press the enter key, a new row is inserted below the selected cell.
Doesn't it be like this in your environment?
Linux, Qt 4.7.4 or Qt 4.8.0, this codeBehaves as expected.Qt Code:
#include <QtGui> int main(int argc, char *argv[]) { tw.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
Do you have an active push button elsewhere in the UI that adds a row?
Thank you for reply.
You've hit the nail on the head.
I have several buttons on the table widget, and one of them right below the QTableWidget is connected to a slot that inserts a row.
I found that the button is somehow also selected every time I clicked a cell in the table and the slot is called when the enter key is pressed after that.
I don't know how this happens...
It will be related to the presence of default and auto-default buttons on the dialog. If you press Enter when not editing a cell of your table then one of the buttons will be triggered. When editing a cell the table should swallow the Enter keypress.
lain (29th March 2012)
Thanks for telling me about "default" and "autoDefaut" properties of a button.
This may not be the best solution, but I worked around by turning off autoDefault property of all the buttons.
Bookmarks