PDA

View Full Version : Modal Dialog requires 2 clicks of ok to close, Modeless only 1



qtnewbie2017
31st October 2017, 20:20
Linux Touchscreen Device.
[1] Creating simple MessageBox (0k button) using exec() requires 2 clicks to close
[2] Creating one with msgBox->setWindowModality(Qt::NonModal); msgBox->Show() requires just 1 click.
If do not call msgBox->setWindowModality(Qt::NonModal); in [2] then need 2 clicks.
So seems if window is modal need 2 clicks.
Any ideas what could cause this? The message box itself is being created as result of push button click

d_stranz
31st October 2017, 23:06
Any ideas what could cause this?

Not without seeing the code you use to create and show the message box, as well as the slot and code you use to connect to the push button signals.

Please read my signature (below) on how to post code.

qtnewbie2017
2nd November 2017, 12:36
The 2-click issue disappears if I use clicked() for the pb connection instead of pressed() ... debug tells me that the pressed signal is NOT being emitted twice though, so no idea why using pressed() would have this side-effect. The reason I was using QPushButton::pressed instead ofQPushButton::clicked was because the "clicked" was not responsive, as though focus was being lost between the pressed and release actions.




//This called in MainWindow::Init() function
// If use QPushButton::pressed then 2 clicks required to close window
// If use QPushButton::clicked then the pb itself is not responsive

bConnected = connect(ui->pB_VerDlg, &QPushButton::pressed,this, &MainWindow::ShowVersionBox);
if (!bConnected) printf("failed to connect clicked() to ShowVersionBox()\n");

---

void MainWindow::ShowVersionBox() {
QMessageBox msgBox;

printf("======> Handling PB click\n");

msgBox.setWindowTitle("");
msgBox.setText("Applications List");
msgBox.setFont(fontBold);
msgBox.setStyleSheet(QString::fromUtf8("background-color: rgb(0, 75, 141); color: white; "));

msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.button(QMessageBox::Ok)->setFont(fontBold);
msgBox.button(QMessageBox::Ok)->setMinimumSize(QSize(70*HMI_SCALE, 40*HMI_SCALE));
msgBox.setInformativeText("All info");

// Close box after 30s if left open
QTimer::singleShot(CLOSE_WINDOW_MS, &msgBox, SLOT(close()));

msgBox.exec() ;
}

d_stranz
2nd November 2017, 23:03
The connect() call in your MainWindow::Init() method has nothing to do with closing the message box, it concerns when the slot that creates and posts the message box is invoked.