1

I am having this trouble with QMessageBox:

QMessageBox box;
box.setWindowTitle(tr("Warning box"));
box.setIcon(QMessageBox::Warning);
box.setText(tr("Something happened, see details or press OK"));
box.setDetailedText("There is a detail. World is not answering to Hello, try to say Hello world again!");
box.setStandardButtons(QMessageBox::Ok);
box.setDefaultButton(QMessageBox::NoButton);
box.exec();

If I do:

box.setDefaultButton(QMessageBox::NoButton);

the OK button is still marked as default.

I did not find the QMessageBox::ShowDetails enum, so I cannot set as default button the Show details push button.

Is there any way to accomplish this?

scopchanov
  • 7,966
  • 10
  • 40
  • 68
  • 1
    In my case without using setDefaultButton() the default button is `See details ...`, why do you say that Ok Button is selected by default? Could you show an image or some proof of what it says? great to indicate your OS and version of Qt5 – eyllanesc Oct 12 '18 at 12:57
  • Thank you for your feedback. Now I am on another project. ASAP I will answer (during these week). – Armin the Crossman Oct 15 '18 at 14:39
  • Really sorry guys. Trying hard. From that time a did not solute the problem, because it was marked as "not important". So I am far behind this. Thank you for understanding. Thank you for your tips and advices. – Armin the Crossman Nov 15 '18 at 13:56

1 Answers1

1

I would suggest you to use QMessageBox::setDefaultButton in order to set the first QPushButton, which is a child of your QMessageBox, as default like this:

if (!box.detailedText().isEmpty())
        box.setDefaultButton(box.findChildren<QPushButton *>().first());
scopchanov
  • 7,966
  • 10
  • 40
  • 68