Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Beginner question: How to tell when Dialog is exposed?



  • A beginner question:

    I need to be aware when a dialog is exposed. showEvent() only is called when the panel is shown. If a panel then covers the first dialog, when that second panel goes away, my first dialog needs to check a parameter but it currently has no idea the covering panel has been closed.

    Is there a callback or delegate routine that gets called when a dialog is exposed after a covering window goes away?


  • Lifetime Qt Champion

    @mstoth By "exposed" you mean "has focus"?



  • Yes, the dialog invokes another dialog both of which are full screen (on a beaglebone). Once the covering dialog goes away the focus is returned to the covered dialog which is now exposed. If I try to use focusInEvent however, this routine does not get called when the first dialog is exposed.



  • @mstoth how are you displaying the dialogs, in particular the second one?
    From documentation:

    The most common way to display a modal dialog is to call its exec() function. When the user closes the dialog, exec() will provide a useful return value.



  • These are not modal.
    In the first dialog, the onRelease handler for one of the buttons is

    void MainMenu::on_configureConsoleButton_released()
    {
        dc=new DialogConsoleConfigA(this);
        dc->show();
    }
    

    DialogConsoleConfigA covers the main menu dialog.
    Then when DialogConsoleConfigA is removed,

    void DialogConsoleConfigA::on_pushButton_released()
    {
        this->hide();
    }
    
    

    Now the first dialog is exposed again. I need to find a way for the MainMenu dialog to be aware that the DialogConsoleConfigA dialog has been hidden.



  • @mstoth
    use signal slot mechanism.

    Dialog *dialog = new Dialog;
    connect(dialog, &Dialog::rejected, this, [=](){
        //something
    });
    dialog->show();
    

    or in your Dialog class listen a closeEvent:

    void Dialog::closeEvent (QCloseEvent *event) {
         emit closed();
    event->accept();
    }
    

    .h file:

    signals:
    void closed();
    
    protected:
    void closeEvent(QCloseEvent *event);
    
    Dialog *dialog = new Dialog;
    connect(dialog, &Dialog::closed, this, [=](){
        //something
    });
    dialog->show();
    


  • This post is deleted!


  • @Taz742 said in Beginner question: How to tell when Dialog is exposed?:

    connect(dialog, &Dialog::rejected, this, =

    Hi, why rejected?



  • @Diracsbracket
    When form 'X' button click, when a dialog is closed QDialog does not call a rejected signal ?



  • @Taz742 said in Beginner question: How to tell when Dialog is exposed?:

    When form 'X' button click, when a dialog is closed QDialog does not call a rejected signal

    Yes, but when you reject a config dialog, then that usually means nothing needs to be done...? I would have used the accepted() signal. But hey, let's wait and see what exactly @mstoth has in mind.



  • @Diracsbracket
    I think no one is right, he only wants to hide the dialog? Waiitt ))



  • @Taz742 said in Beginner question: How to tell when Dialog is exposed?:

    he only wants to hide the dialog

    @mstoth said in Beginner question: How to tell when Dialog is exposed?:

    when that second panel goes away, my first dialog needs to check a parameter

    I think he wants to check if any of the settings were changed when the dialog was closed^^. In any case, thanks for posting the solution!



  • Indeed, all I need to do is see if something has happened when the first dialog is visible again. I thought about signals/slots but there is more than one case where this first dialog becomes visible again. For instance, the first dialog has 6 buttons, each presents a different new dialog. When any of those appear, they hide the first one. To use signals, i'd have to connect to each of those 6 dialogs.

    I was hoping for something more elegant like a event handler I could override in the first dialog that gets called when the first dialog becomes visible again. (something like onExposed()) . I have not seen anything like that.

    Thanks by the way for all the help! I appreciate your thoughts.



  • @mstoth
    Good! I think you have an idea of what to do. Then mark this topic to be solved.



  • ok, so my solution is to use signals to indicate the condition i'm interested in. It's a bit messy since there are so many places I need to connect to but from what I'm hearing, that is the only way.

    I'll mark it as solved but unfortunately it is not the kind of solution I was hoping for. If anyone else has a more elegant way of handling this feel free to let me know.

    I do appreciate everyone's time and effort on this problem! Thank you very much.


Log in to reply