slot - Qt: Issuing a message before emitting a signal -


brief description of application , question:

in qtabwidget have several groupboxes containing each 2 qradiobuttons. e.g. select menu (groupbox): (radiobutton:) (radiobutton:) b

at 1 point of time, 1 menu can active. both radiobuttons connected each othe -> when click radiobutton , set true, radiobutton b automatically set false - , other way round.

when trying change menu setting, before click signal emitted, issue qmessagebox warning "are sure want change menu? can cause severe damage device." -yes/no.

when clicking yes, change menue setting. when clicking no, remain before.

the problem have is: when issuing qmessagebox in on_radio_button_toggled slot, radiobutton state has changed true. if change state in slot again , correct them, looks state has changed when pop message shows up. don't want because implies state of menue has changed.

where or how can let qmessagebox pop before emitting actual signal slot - when clicking radio button?

thank help.

update: have implemented eventfilter recommended. here source code:

ui->radiobuttonmenu1->installeventfilter(this); ui->radiobuttonmenu2->installeventfilter(this); 

submenuone qwidget. integrated mainwindow qtabwidget (via placeholder).

bool submenuone::eventfilter(qobject *obj, qevent *event) { if(event->type() == qevent::mousebuttonpress) { qmessagebox::standardbutton reply; reply= qmessagebox::question(this,tr("warning"),tr("changing settings   may cause severe damage device! please confirm decision."),qmessagebox::yes|qmessagebox::no);  if (reply == qmessagebox::yes) {  //qmouseevent *mouseevent = static_cast<qmouseevent *>(event);    //keyevent->accept();    //event->accept();    qdebug("yes.");     return false; } else {     qdebug("no.");       return true; }  } } 

you have use bool eventfilter(qobject *obj, qevent *event); declare event filter in window, instal event filter every radiobutton this: radiobutton1->installeventfilter(this);. @ eventfilter check event type: if (event->type() == qevent::mousebuttonpress) , show qmessagebox. can accept event , return true or false depending on user choise.

bool submenuone::eventfilter(qobject *obj, qevent *event) {   if(event->type() == qevent::mousebuttonpress)   {     qmessagebox::standardbutton reply;     reply= qmessagebox::question(this,tr("warning"),tr("changing settings   may cause severe damage device! please confirm decision."),qmessagebox::yes|qmessagebox::no);      if (reply == qmessagebox::yes)     {         static_cast<qradiobutton*>(obj)->setchecked(true);     }     event->accepted();     return true;   }   return qmainwindow::eventfilter(obj, event); //you forget this. qmainwindow base class of submenuone. } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -