Home > Back-end >  Remove icons on buttons in QMessageBox
Remove icons on buttons in QMessageBox

Time:09-22

There is an output message with three buttons:

QMessageBox messageBox(QMessageBox::Question, tr(""), tr(""), QMessageBox::No | QMessageBox::Yes | QMessageBox::Cancel, this);
messageBox.setButtonText(QMessageBox::No, tr("1"));
messageBox.setButtonText(QMessageBox::Yes, tr("2"));
messageBox.setButtonText(QMessageBox::Cancel, tr("Cancel"));
auto response = messageBox.exec();

Please tell me how to remove the standard icons that are highlighted in the red square?

enter image description here

CodePudding user response:

I can't reproduce it on Windows but you could try to add custom buttons to message box

QMessageBox messageBox(QMessageBox::Question, tr(""), tr(""), QMessageBox::NoButton, this);

QPushButton* noButton = new QPushButton(&messageBox);
noButton->setText(tr("1"));
messageBox.addButton(noButton, QMessageBox::NoRole);

QPushButton* yesButton = new QPushButton(&messageBox);
yesButton->setText(tr("2"));
messageBox.addButton(yesButton, QMessageBox::YesRole);

QPushButton* cancelButton = new QPushButton(&messageBox);
cancelButton->setText(tr("Cancel"));
messageBox.addButton(cancelButton, QMessageBox::RejectRole);

auto response = messageBox.exec();

CodePudding user response:

Could you try:

QMessageBox messageBox(this);
messageBox.addButton(tr("1"), QMessageBox::NoRole);
messageBox.addButton(tr("2"), QMessageBox::YesRole);
messageBox.addButton(tr("Cancel"), QMessageBox::RejectRole);
auto response = messageBox.exec();
  • Related