actually the question in the header: How to set the name specifically for the "Show details" button; there are no problems with other buttons.

QMessageBox messageBox; messageBox.setText("Текст"); // Изменить текст стандартной кнопки (проблем нет) messageBox.addButton("Отменить", QMessageBox::Cancel) // Здесь отображаются детали по нажатию кнопки "Show details" и "Hide details" // текст кнопки меняется в зависимости от состояния кнопки (стандартное поведение) // После добавления текста, кнопка создается по умолчанию messageBox.setDetailedText("Детали"); 

How to change the text of this button to your own? This button does not have a standard role (I did not find it), it is created automatically when setting text to the setDetailedText () function, I cannot get access to it, standard buttons created by default do not store buttons () , but because we added the Cancel button and its text to it using the addButton () function only stores it in the list, it doesn’t work to track down the "Show details" button or not.

UPDATE

A little thought, it turned out such an example, but it still does not work correctly, the text is reset.

 #include "mainwindow.h" #include "ui_mainwindow.h" #include <QMessageBox> #include <QAbstractButton> #include <QTextEdit> #include <QPushButton> #include <QList> #include <QDebug> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); box = new QMessageBox; box->setDetailedText("Детали"); QList<QAbstractButton*> listButtons = box->buttons(); QPushButton *pushButton = NULL; for (QList<QAbstractButton*>::iterator it = listButtons.begin(); it != listButtons.end(); ++it) { QAbstractButton * button = *it; if (box->buttonRole(button) == QMessageBox::ActionRole) { pushButton = qobject_cast<QPushButton*>(button); } } if (pushButton) { // Хотим видеть состояние нажатия кнопки pushButton->setCheckable(true); // Текст отоброжается, но не влазит (Он отображается и в виджете, до первого клика по кнопке) pushButton->setText("Показать детали"); // А вот размер кнопки не изменяется pushButton->resize(QSize(200, 50)); connect(pushButton, SIGNAL(toggled(bool)), this, SLOT(onClick(bool))); } box->exec(); } MainWindow::~MainWindow() { delete ui; } void MainWindow::onClick(bool click) { QPushButton * button = qobject_cast<QPushButton*>(sender()); // Видим пока еще текст "Показать детали" qDebug() << button->text(); if (click) { button->setText("Скрыть детали"); } else { button->setText("Показать детали"); } // Видим свой текст только в дебаге, но в самом виджете он не изменился, а возвратился на Hide Details qDebug() << button->text(); // При следующих кликах видим только Show Details/Hide Details нами заданный текст не отображает } 
  • What version of Qt are we talking about? - vegorov pm
  • Qt version 4.8.5, inserted an example, but it still does not display text on clicks. - Disastricks pm
  • On version 5.12, my example also compiles and works as in 4.8.5, that is, no changes. - Disastricks 5:19 pm

0