Ok, I think nobody is interested in this topic but I will post my progress here.
I think my solution is not the best, I had to stop the propagation of the events in order to avoid the destruction of the editor.
Was necessary to analyse 3 types of events: keyboard, mouse click in the property browser and mouse click outside the property browser.
The events of the keyboard should be handle in the editor delegate, since was installed an event filter in the editor widget:
bool QtPropertyEditorDelegate
::eventFilter(QObject *object,
QEvent *event
) {
...
if (event
->type
() == QEvent::KeyPress) {
QKeyEvent *e
= static_cast<QKeyEvent
*>
(event
);
if ( e->key() == Qt::Key_Tab ||
e->key() == Qt::Key_Return ||
e->key() == Qt::Key_Enter )
{
// make the necessary validation
if ( isNotValid )
{
event->accept();
return true;
}
}
...
}
bool QtPropertyEditorDelegate::eventFilter(QObject *object, QEvent *event)
{
...
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *e = static_cast<QKeyEvent *>(event);
if ( e->key() == Qt::Key_Tab ||
e->key() == Qt::Key_Return ||
e->key() == Qt::Key_Enter )
{
// make the necessary validation
if ( isNotValid )
{
event->accept();
return true;
}
}
...
}
To copy to clipboard, switch view to plain text mode
Is important to stop the event propagation when the value is invalid.
For the mouse click outside the property browser is necessary to add in the eventFilter of the editor delegate the same check but now for the focus out event. The reason of the focus out in this case is Qt::OtherFocusReason, that is done by the popup dialog:
if (event
->type
() == QEvent::FocusOut) {
if ( fe->reason() == Qt::OtherFocusReason )
{
// make the necessary validation
if ( isNotValid )
{
event->accept();
return true;
}
}
}
if (event->type() == QEvent::FocusOut)
{
QFocusEvent *fe = static_cast<QFocusEvent *>(event);
if ( fe->reason() == Qt::OtherFocusReason )
{
// make the necessary validation
if ( isNotValid )
{
event->accept();
return true;
}
}
}
To copy to clipboard, switch view to plain text mode
In the last case, the click in another part of the property browser, the event is catch by the QtPropertyEditorView:
void QtPropertyEditorView
::mousePressEvent(QMouseEvent *event
) {
...
if ( isNotValid )
{
edit(index);
return;
}
...
}
void QtPropertyEditorView::mousePressEvent(QMouseEvent *event)
{
...
if ( isNotValid )
{
QModelIndex index = currentIndex();
edit(index);
return;
}
...
}
To copy to clipboard, switch view to plain text mode
The reason to interrupt the event is to avoid that the event arise in the QItemDelegate::event, so that the editor is not destroyed. When the message box popup, the editor loses the focus but is still there, then when the message box is closed the focus goes to the right place.
Bookmarks