Popup a qmessagebox from a qmessagebox



  • I set a button in the MainWindow
    when I click it, a messagebox will popup, which contains two buttons: yes and no
    then when I click yes, another messagebox will popup.
    BUT when the second messagebox popup, the first one will disappear. and if I close the second one, the first will come out.

    what I want is we can see the first one messagebox even if the second one popup but we can do nothing for the first one when the second one is not close.

    can u help me?
    thx in advance

    here is my code:
    @
    QMessageBox firstone;
    firstone.setStandardButtons(QMessageBox::Ok | QMessageBox::No);
    if(firstone.exec() == QMessageBox::Ok)
    {
    QMessageBox secondone;
    secondone.exec();
    }
    @



  • Hmm, the exec code will run until the OK or NO button is pressed, so it is strange that the first one reappears when the second one is closed.
    If you really want this to work, you should inherit a QMEssageBox class and alter the OK button signal to open a new messageBox if not already opened. The way you do so now it is not able to display both!


  • Moderators

    That sounds like an annoying UI design decision, be careful :)

    To get that functionality, you need to subclass QMessageBox and open the second one from within the first, before it is killed. Should not be too hard, but you will need to experiment a bit.



  • really? we have no other choice?

    this is not strange.
    imagine u are saving a file, a window where we can enter a filename will popup. but if there have been a file whose name is exactly what u just entered, another window will pupup and tell u : do u want to replace it? or something like this. and when this window is not close, the last window(where u enter the filename) is always there.

    [quote author="Jeroentje@home" date="1389963475"]Hmm, the exec code will run until the OK or NO button is pressed, so it is strange that the first one reappears when the second one is closed.
    If you really want this to work, you should inherit a QMEssageBox class and alter the OK button signal to open a new messageBox if not already opened. The way you do so now it is not able to display both![/quote]



  • I got u.

    thx a lot.

    [quote author="sierdzio" date="1389963594"]That sounds like an annoying UI design decision, be careful :)

    To get that functionality, you need to subclass QMessageBox and open the second one from within the first, before it is killed. Should not be too hard, but you will need to experiment a bit.[/quote]


  • Moderators

    [quote author="bear234" date="1389963777"]really? we have no other choice?

    this is not strange.
    imagine u are saving a file, a window where we can enter a filename will popup. but if there have been a file whose name is exactly what u just entered, another window will pupup and tell u : do u want to replace it? or something like this. and when this window is not close, the last window(where u enter the filename) is always there.
    [/quote]

    Yes, really. That is how it is being done in case you mentioned (although not using message boxes, but QDialogs).


  • Moderators

    [quote author="bear234" date="1389963777"]really? we have no other choice?

    this is not strange.
    imagine u are saving a file, a window where we can enter a filename will popup. but if there have been a file whose name is exactly what u just entered, another window will pupup and tell u : do u want to replace it? or something like this. and when this window is not close, the last window(where u enter the filename) is always there.
    [/quote]

    i also would discourage from using message boxes for that.
    A more friendly solution would be to display a warning text (or an icon with an tooltip for example) under/beside the line edit saying that the file does already exist.
    And only enable the button to proceed when all requirements are fulfilled.

    I personally like such "inline" solutions the most rather than annoying popups.



  • OK I understand.

    thx
    [quote author="sierdzio" date="1389963869"][quote author="bear234" date="1389963777"]really? we have no other choice?

    this is not strange.
    imagine u are saving a file, a window where we can enter a filename will popup. but if there have been a file whose name is exactly what u just entered, another window will pupup and tell u : do u want to replace it? or something like this. and when this window is not close, the last window(where u enter the filename) is always there.
    [/quote]

    Yes, really. That is how it is being done in case you mentioned (although not using message boxes, but QDialogs).[/quote]



  • thx a lot!

    nice method.

    [quote author="raven-worx" date="1389967933"][quote author="bear234" date="1389963777"]really? we have no other choice?

    this is not strange.
    imagine u are saving a file, a window where we can enter a filename will popup. but if there have been a file whose name is exactly what u just entered, another window will pupup and tell u : do u want to replace it? or something like this. and when this window is not close, the last window(where u enter the filename) is always there.
    [/quote]

    i also would discourage from using message boxes for that.
    A more friendly solution would be to display a warning text (or an icon with an tooltip for example) under/beside the line edit saying that the file does already exist.
    And only enable the button to proceed when all requirements are fulfilled.

    I personally like such "inline" solutions the most rather than annoying popups. [/quote]



  • Why not calling the second MessageBox outside the first one?
    I would open the first MessageBox and wait for it to be closed. When closed a buttonClicked() signal is emitted. You connect a slot to the first QMessageBox's buttonClicked() signal, and in that slot you call the second QMessageBox.
    @QMessageBox firstMessage;
    (...)
    connect(&firstMessage, SIGNAL(buttonClicked(QAbstractButton *)), this, SLOT(onFirstMsgClosed(QAbstractButton * button)));
    (...)
    slots:
    void onFirstMsgClosed(QAbstractButton * button){
    QMessageBox secondMessage;
    secondMessage.show();
    }
    @

    The code above is quite incomplete, but I hope you get it.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.