How can I resize QMessageBox?

前端 未结 5 665
没有蜡笔的小新
没有蜡笔的小新 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条回答
  •  旧时难觅i
    2020-12-15 07:04

    You can edit the css of the label:

    msg.setStyleSheet("QLabel{min-width: 700px;}");
    

    You can similarly edit the css of the buttons to add a margin or make them bigger.

    For example:

    msg.setStyleSheet("QLabel{min-width:500 px; font-size: 24px;} QPushButton{ width:250px; font-size: 18px; }");
    

    There is also a trick mentioned:

    QSpacerItem* horizontalSpacer = new QSpacerItem(800, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
    QGridLayout* layout = (QGridLayout*)msg.layout();
    layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
    

    But this doesn't seem to work for everyone.

提交回复
热议问题