How can I resize QMessageBox?

前端 未结 5 664
没有蜡笔的小新
没有蜡笔的小新 2020-12-15 06:11

I have a QMessageBox which I\'d like it to be bigger. It\'s a simple QMessageBox with two standard buttons, Ok and Cancel. The problem is that it i

5条回答
  •  悲哀的现实
    2020-12-15 06:56

    Inspired by the "inspect the Qt source code and adapt" approach, this worked for me with Qt 5.12:

    if (auto grid = dynamic_cast(msgBox.layout())) {
        if (auto text = grid->itemAtPosition(0, grid->columnCount() - 1); text && text->widget()) {
            text->widget()->setFixedWidth(500);
        }
    }
    

    Keep in mind, of course, that this will break if ever they change the way they do layouts of QMessageBox.

提交回复
热议问题