How can I resize QMessageBox?

前端 未结 5 655
没有蜡笔的小新
没有蜡笔的小新 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 07:08

    coyotte508's answer caused my layout to be horribly off center and at different widths it was cut off. In searching around further I found this thread which explains a better solution.

    In essence the layout of a messagebox is a grid, so you can add a SpacerItem to it to control the width. Here's the c++ code sample from that link:

    QMessageBox msgBox;
    QSpacerItem* horizontalSpacer = new QSpacerItem(500, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
    msgBox.setText( "SomText" );
    QGridLayout* layout = (QGridLayout*)msgBox.layout();
    layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
    msgBox.exec();
    

提交回复
热议问题