c++ - QWidget setFocus does nothing -
i implementing custom context menu widget called gripmenu containing several other widgets. if user left clicks, menu should appear. hide or delete if user clicks outside of it, need somehow check if user click somewhere else. plan ask child widgets ->hasfocus() , if none hasfocus, close menu. unfortunately can't set focus. why? code is:
gripmenu = new gripmenu(this); gripmenu->setfocus(); and in gripmenu's constructor:
gripmenu::gripmenu(){ [... set things up] ui->lineedit->setfocus(); // or other widget focus, // this->setfocus() not work: see below: qdebug() << ui->lineedit->hasfocus(); // returns false! } how possible there no focus after set it?
at end goal mimic typical context-menu behaviour (meaning menu closed when clicked somewhere else). if have better suggestions on how tackle it, please hint me way!
edit:
i got working. hint of frank osterfeld useful. still had add "gripmenu->activate()" in widget "a" created(needed) gripmenu, because without it, active widget still "a" after mouse got released.
Comments
Post a Comment