MessageBox with QT

Solved
Aissa -  
 Aissa -

Hello. I hope I’m in the right forum. I’m using Qt for a C++ program.
I have a confirmation messageBox as follows:

 QMessageBox msgBox; msgBox.setWindowTitle("Confirmation"); msgBox.setText("Voulez-vous vraiment le faire ?"); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setDefaultButton(QMessageBox::Yes); 

And I wanted to know if it’s possible to change the names of the yes/no buttons. I want to put "Oui" or "Non" instead since my application is entirely in French.

Is this possible with Qt? Any answer is welcome. Thanks!

1 answer

  1. Noa
     
    Good evening, Yes, it is possible to change the text of the "Yes" and "No" buttons in a QMessageBox using the setButtonText() methods of QMessageBox. Here is how you could do it in your case:
    QMessageBox msgBox; 
    msgBox.setWindowTitle("Confirmation"); 
    msgBox.setText("Voulez-vous vraiment le faire ?");
    msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); 
    msgBox.setDefaultButton(QMessageBox::Yes); // Change the text of the Yes and No buttons
    msgBox.setButtonText(QMessageBox::Yes, "Oui"); 
    msgBox.setButtonText(QMessageBox::No, "Non");
    
    This should display the buttons "Oui" and "Non" in your confirmation message box. It is also possible to specify the button texts during the creation of the QMessageBox object using the question() method of QMessageBox:
    QMessageBox::StandardButton reply; 
    reply = QMessageBox::question(this, "Confirmation", "Voulez-vous vraiment le faire ?", 
    QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
    
    In this case, the texts of the "Yes" and "No" buttons can be specified using the strings "Oui" and "Non" respectively:
    QMessageBox::StandardButton reply; 
    reply = QMessageBox::question(this, "Confirmation", "Voulez-vous vraiment le faire ?", 
    QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes, "Oui", "Non");
    
    I hope this answers your question! Have a good evening!
    1
    1. Aissa
       

      Thank you very much!

      0