Skip to content

QtWS: Super Early Bird Tickets Available!

  • 0 Votes
    16 Posts
    24k Views
    G

    I created a new project with 2 dialogs, the sources are mainwindow.cpp and dialog.cpp.
    The code in dialog.cpp looks like this:

    #include "dialog.h" #include "ui_dialog.h" Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); } Dialog::~Dialog() { delete ui; } void Dialog::message() { QMessageBox::StandardButton reply; reply = QMessageBox::information(this, "Confirmation","<b><font size='16' color='green'>Do you want to close the 2nd window?</font></b>",QMessageBox::Yes | QMessageBox::No); if(reply == QMessageBox::Yes) { qDebug() << "Yes was clicked. Close 2nd."; this->reject(); } else { qDebug() << "No was clicked. Don't close 2nd."; } } void Dialog::on_pushButton_clicked() { message(); }

    When I click yes, it does what I want, it closes dialog. When I use the same code in my original application, it does nothing (no error message either). What can cause this completely different behavior? Thank you.

  • 0 Votes
    4 Posts
    1k Views
    mrjjM

    @namit
    ok super.

  • 0 Votes
    9 Posts
    8k Views
    michaelLM

    My solution for automatically close a Dialog in qml by clicking outside the window was to change the modality of the window to non modal:

    Dialog { id: myDialog height: 300 width: 600 modality: Qt.NonModal ...

    My window has a 1280x800 size and the dialog appears in the middle. Once its open i click outside and the Dialog closes by itself.