PDA

View Full Version : how to customize edit key in QTableView?



apango
6th April 2013, 06:32
Hi, everyone.
How to customize a edit key in QTableView?

I use a customized delegate to edit data in model. The cell editor can be triggered by a way defined by setEditTriggers ( EditTriggers ).
But I don't find a way to define custom key, such an enter or some other key. There are only 7 trigger types, but no one is what I need.

Thank you.

ChrisW67
6th April 2013, 07:50
Use a QShortcut, connect the activated() signal to a slot, and call the view's edit() slot. Something like:


class Table: public QTableView
{
Q_OBJECT
public:
Table(QWidget *p = 0): QTableView(p) {
QShortcut *s = new QShortcut(QKeySequence(tr("Ctrl+;")), this);
connect(s, SIGNAL(activated()), SLOT(editActivated()));
}
private slots:
void editActivated() {
edit(currentIndex());
}
};


If you intercept Enter to start and edit you may lose it as a way to end the edit as it is by default.