Important: Please read the Qt Code of Conduct -

Qt messagebox stylesheet

  • Hi everyone.
    I am new to Qt. I am currently learning my way around Qt and need some help.
    For context, I am checking a variable every 20sec with a function call. If the variable is set, a message box appears. This works, but it is the colour of the text and buttons I need to modify because my background is black.

    This is my function:

    void MainWindow::connectionStatus()
        Socket conn_checker;
            // Pop-up window with connection warning
            QMessageBox msg(this);
            msg.critical(this,"Connection warning","<font color=\"White\">The remote is not connected to the amplifiers <br>Please check connection");
            //msg.setStyleSheet("QMessageBox:{ background-color:red;}");
            // Set connection status led to red
            ui->stat_Label->setText("Not connected!");

    I have managed to get the text white, but when it comes to the buttons of background I have tried some approaches but none have worked so far.

    How can I make this happen?

  • Lifetime Qt Champion

    @frodi critical() is a static method - setting stylesheet on a QMessageBox instance and then calling a static method does not make sense (also, you set stylesheet after calling critical).

Log in to reply