Yes, I suppose the problem is in my code already. It is quite difficult to give all the information. What I can provide is some code. What I do is I create a QGraphicsWidget with a QGraphicsWidget as a child which should represent a button:
FS_CallingDialog
* dialog
= new FS_CallingDialog
(QString((const char*)identity
), conv
);
dialog->button->focusedPenColor = Qt::white;
dialog->button->notFocusedPenColor = Qt::black;
dialog->button->setNavigationFocus();
FS_CallingDialog* dialog = new FS_CallingDialog(QString((const char*)identity), conv);
dialog->button->focusedPenColor = Qt::white;
dialog->button->notFocusedPenColor = Qt::black;
dialog->button->setNavigationFocus();
To copy to clipboard, switch view to plain text mode
the constructor of the class calls the base class constructor which in turn invokes its own base class (QGraphicsWidget) constructor. What I do in the constructor of FS_CallingDialog is:
title->setText(tr("..."));
targetDisplayLabel->setText(targetDisplayName);
button = new LoginButton(this);
button->setText(tr("..."));
connect(button, SIGNAL(okKeyPressed()), this, SLOT(fadeOut()));
connect(button, SIGNAL(okKeyPressed()), this, SLOT(deleteLater()));
// Position the items.
centerHInParent(title);
centerHInParent(targetDisplayLabel);
centerHInParent(button);
title->setPos(title->pos().x(), 10);
targetDisplayLabel->setPos(targetDisplayLabel->pos().x(), boundingRect().height()/3);
button->setPos(button->pos().x(), boundingRect().height()*2/3);
this->conv = conv;
QGraphicsSimpleTextItem* title = new QGraphicsSimpleTextItem(this);
title->setText(tr("..."));
QGraphicsSimpleTextItem* targetDisplayLabel = new QGraphicsSimpleTextItem(this);
targetDisplayLabel->setText(targetDisplayName);
button = new LoginButton(this);
button->setText(tr("..."));
connect(button, SIGNAL(okKeyPressed()), this, SLOT(fadeOut()));
connect(button, SIGNAL(okKeyPressed()), this, SLOT(deleteLater()));
// Position the items.
centerHInParent(title);
centerHInParent(targetDisplayLabel);
centerHInParent(button);
title->setPos(title->pos().x(), 10);
targetDisplayLabel->setPos(targetDisplayLabel->pos().x(), boundingRect().height()/3);
button->setPos(button->pos().x(), boundingRect().height()*2/3);
this->conv = conv;
To copy to clipboard, switch view to plain text mode
My problem is that the button never seems to get the focus. The constructor of the LoginButton is:
resize(40, 10);
setFocusPolicy(Qt::StrongFocus);
setFlag(ItemIsFocusable, true);
focusedPenColor = Qt::white;
notFocusedPenColor = Qt::white;
resize(40, 10);
setFocusPolicy(Qt::StrongFocus);
setFlag(ItemIsFocusable, true);
focusedPenColor = Qt::white;
notFocusedPenColor = Qt::white;
To copy to clipboard, switch view to plain text mode
and the setNavigationFocus() method is implemented this way:
// Set the focus to the item.
setFocus();
update(boundingRect());
// Set the focus to the item.
setFocus();
update(boundingRect());
To copy to clipboard, switch view to plain text mode
It seems that pressing the button, the keyPressEvent(...) method invoked is not that of the LoginButton, but that of the QGraphicsPixmapItem which was focused before it.
I use the same code in other parts of my project and seems to work there. Do you notice anything wrong in here? Of course the mistake might be somewhere else... 
Thanks.
Bookmarks