Search code examples
c++qt5qmessagebox

How to change stylesheet of QMessageBox button?


I want to chanhe the background colour and font of QMessageBox button? Any help will be greatly appreciated.


Solution

  • #include <QtWidgets>
    
    int main(int argc,char* argv[])
    {
        QApplication app(argc,argv);
        QMessageBox msgBox(QMessageBox::Information,
                   "QMessageBox Background Color",
                   "This is QMessageBox with Different Background Color");
    
        //Change background color
        QPalette palette;
        palette.setColor(QPalette::Background, Qt::cyan);
        msgBox.setPalette(palette);
    
        //Change font
        QFont font( "Tokyo" );
        font.setPointSize( 32 );
        font.setWeight( QFont::Bold );
        font.setItalic( TRUE );
        msg->setFont(font);
    
        msg->exec();
    
        msgBox.show();
        return app.exec();
    }
    

    For more on stylesheet http://doc.qt.io/qt-4.8/stylesheet-syntax.html