QLineEdit and keyPressEvent(QKeyEvent *)
I've subclassed QLineEdit in order to obtain field that will be used for acquiring accelerators from user (sth like class derived from QListViewItem in QtDesigner). Unfortunately despite the fact I've reimplemented keyPressEvent(QKeyEvent *) I still cannot catch Ctrl+A and Ctrl+U. I browsed source code of QLineEdit but I still have no idea.
Code:
#ifndef LINEACCEL_H
#define LINEACCEL_H
#include <qkeysequence.h>
#include <qlineedit.h>
{
Q_OBJECT
public:
~LineAccel();
protected:
QPopupMenu * createPopupMenu();
private:
int translateModifiers(int);
private:
};
#endif
#include "lineaccel.h"
{
setReadOnly(true);
setAccel(accel);
}
LineAccel::~LineAccel()
{
}
{
ks = a;
setText(ks);
}
{
return ks;
}
QPopupMenu * LineAccel::createPopupMenu()
{
return 0;
}
{
int nextKey = e->key();
if (nextKey
== QObject::Key_Control ||
return;
int modifier = translateModifiers(e->state());
nextKey |= modifier;
}
int LineAccel::translateModifiers(int state)
{
int result = 0;
if (state
& QObject::ControlButton)
return result;
}
Re: QLineEdit and keyPressEvent(QKeyEvent *)
Thing I know is that Ctrl+A is never passed to keyPressEvent. I've installed my event filter but it also didn't help.
Re: QLineEdit and keyPressEvent(QKeyEvent *)
I'd suggest "stealing" Designer's code.
Re: QLineEdit and keyPressEvent(QKeyEvent *)
Designer uses QListViewItem. I switched to KListView because there is no hope to find out what's wrong with QLineEdit. Something is filtering Ctrl+A before sequence reaches recently installed event handler. Some magic behind ;[
Re: QLineEdit and keyPressEvent(QKeyEvent *)
QObject::event() probably :)
And Ctrl+A is probably a shortcut to "Select all", so you might need to disable the shortcut.
Re: QLineEdit and keyPressEvent(QKeyEvent *)
But how disable shortcut?
event() - no.
I think event is first passed through event filter chain, then to event() and finally to specific event function:
event
|
event filter (n) -> event filter (n - 1) -> ... -> event filter (0) -> event() -> keyPressEvent(), where event filter (n) is latest installed event filter
I cannot catch this sequence at event filter (n) level so it's obvious I won't catch it at event() level.
Re: QLineEdit and keyPressEvent(QKeyEvent *)
Quote:
Originally Posted by
fear
But how disable shortcut?
Hard to say without looking at the code. I'd say it's an action associated with the context menu of the widget.
Quote:
I cannot catch this sequence at event filter (n)
What did you filter it with?