[Qt-interest] Faking / reposting mouse clicks..
Kustaa Nyholm
Kustaa.Nyholm at planmeca.com
Tue Jun 29 18:41:49 CEST 2010
Hi,
I've implemented (for our embeded system) a menu bar. Both the menubar and the menus 'titles' are QPushButtons.
When a button is clicked a QMenu is opened with QMeny->popup(). So far so good.
The problem is that the design brief calls for the associated menu to open if a button in the menu bar is clicked while
a menu is already open. This does not work of course because an open QMenu will eat the click when user clicks
outside the open menu. I've overriden mousePressEvent in QMeny and I can distinquish weather the user clicks
in the menu or outside the menu, but I've not been able to 'pass on' the event to the menubar so that it would
pass it on to the appropriate button.
My code is along these lines (I've tried various variotions of this without luck):
void MyMenu::mousePressEvent(QMouseEvent *e) {
QPoint pos = e->pos();
if (pos.y() >= 0)
QMenu::mousePressEvent(e);
else {
hide();
pos = mapToGlobal(pos);
pos = mMenuBar->mapFromGlobal(pos);
QMouseEvent fe(e->type(), pos, e->button(), e->buttons(), e->modifiers());
QApplication::sendEvent(mMenuBar,&fe);
}
}
Is this feasible? What am I doing wrong?
I'm also open to other approaches to achieve what I'm trying to do.
br Kusti
More information about the Qt-interest-old
mailing list