c++ - How come a Qt mouseReleaseEvent won't fire? -


so, have custom qlabel class i'm using button. when label clicked, background color changes red green. on mouse release event, background goes red. however, if add slot widget's "clicked" signal, mouse release event appears never fired. label stays green. @ moment, have when label clicked, qmessagebox displayed. yet, after messagebox closed, label stays green. tried connecting it's focusoutevent same slot turned background red, yet it's still not working. how can button revert red background after mouse released? hope makes sense. ideas?

#include "ubtn.h" qstring sty  =  "ubtn{background:red;}"; qstring styd =  "ubtn{background:green;}";  qwidget *obj; ubtn::ubtn(qwidget *parent) :     qlabel(parent) {     this->setstylesheet(sty);     connect(this, signal(onblur(bool)), slot(defaultbtn())); }  void ubtn::defaultbtn() {     this->setstylesheet(sty);     this->repaint(); }  void ubtn::downbtn() {     this->setstylesheet(styd);     this->repaint(); }  void ubtn::mousepressevent(qmouseevent *ev) {     downbtn();     emit clicked(); }  void ubtn::mousereleaseevent(qmouseevent *ev)  {     defaultbtn();  }  void ubtn::focusoutevent(qfocusevent *e)  {     qlabel::focusoutevent(e);     emit(onblur(true));  } 

okay, problem when show qmessagebox, qmessagebox becomes active window... when user releases mouse button mousereleaseevent goes qmessagebox rather ubtn.

i think easiest way around problem ubtn call "emit clicked()" mousereleaseevent() method rather mousepressevent(); way button can revert regular color before qmessagebox shown, , therefore active-window-change takes place.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -