i need hide/show main menu function pressing alt key (like in firefox). know how hide , show it, can't highlight menu after showing it. i've tried menubar()->actions()[0].hover(), activatewindow(), setactiveaction(), activate(qaction::hover), nothing helps. how can it? maybe should use winapi functions instead of qt?
bool mainwindow::event(qevent *event){ if (event->type() == qevent::keypress) { qkeyevent *ke = static_cast<qkeyevent*>(event); if (ke->key() == qt::key_alt) { keyreleaseevent(ke); return true; } } return qmainwindow::event(event); } handle alt
void mainwindow::keyreleaseevent (qkeyevent* event) { if (event->key() == qt::key_alt){ if (menubar()->ishidden()){ menubar()->show(); menubar()->setfocus(qt::menubarfocusevent); //here trying highlight menu } else{ menubar()->hide(); { } }
try debug , see happening.
you can like:
if (menubar()->hasfocus()) qdebug() << " have focus"; else qdebug() << " don't have focus"; and see if has focus works bad or if has no focus think problem... somewhere losing it
a little trick may using:
qtimer::singleshot(0, menubar(), slot(setfocus())); on mainwindow::keyreleaseevent
and last thing... note set focus needs focuspolicy, maybe this helps you.
Comments
Post a Comment