PDA

View Full Version : problem with keypress event and QTableView



ranna
20th March 2009, 12:47
Hi,

I have implemented the keypress event for QTableView and it is working file with enter key. i have reused the eventFilter() function of the QObject.


void ClassXyz::eventFilter(QObject *recv, QEvent *event)
{
if(recv=tableview)
{
if(event->type() == QEvent::KeyPress)
{
QKeyEvent *ke = static_cast<QKeyEvent*>(event);
if(ke->type() == Qt::Key_Tab)
{
//my own operation, move to next cell
}
}
}
else
{
//call QObject's eventFilter
}
}

the above code, says that if i press a tab key in a table view cell's "my own operation-cursor willl move next" has to be executed.

Case 1:
The problem is the eventFilter is not always called if i press the tab key when the cursor is in the cell (cell is in edit mode). i.e i have entered a data in a cell and if i press the tab key, no eventFilter is called and the cursor is not moving to next cell. Instead datachanged signal of the tableview is triggered.

Case 2:
But i have selected the cell (just a single click) and press tab key then the eventFilter function is called and the cursor is moving to next cell with display role.

please tell me what will be problem. it is required for me to resolve the case1.

Thanks
ranna

wysota
21st March 2009, 01:36
What did you install the event filter on?

sigger
21st March 2009, 07:20
I have a similar problem. in my case I am using a delegate with a QTablewidget and a keypress event filter. I've been meaning to create a test case.

Ranna, I assume you are running this on 4.5. Can you test it on 4.4.3? if its short, do you want me to try it?

I had not problem with 4.4.3, but I have the problem with 4.5.0

ranna
23rd March 2009, 10:24
I am using only Qt 4.4

ericV
24th August 2009, 17:13
Hi I'm using QT 4.5 and am trying to implement an eventFilter for my custom delegate.

In short i Have a delegate subclassed from QItemDelegate using a QTextEdit (because i needed Highlighter functionality) and i want the Editor to be singlelined, so it should close whenever i press return.

Does anyone have a tip for me? I am not quite sure how the eventfilter works. And all i got from the documentation is that this filter is used for such a task, but not how.

Thanks

Eric