Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt messagebox stylesheet
Qt 6.11 is out! See what's new in the release blog

Qt messagebox stylesheet

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    frodi
    wrote on last edited by
    #1

    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;
    
        //if(connectionCheck()==false)
        if(tester)
        {
            // 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("background-color:red");
            //msg.setStyleSheet("QMessageBox:{ background-color:red;}");
    
            // Set connection status led to red
            ui->stat_Label->setText("Not connected!");
            ui->stat_Label->setStyleSheet("color:red;");
        }
    
        else
        {
            ui->stat_Label->setText("Connected");
            ui->stat_Label->setStyleSheet("color:green;");
        }
    
    }
    

    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?

    jsulmJ 1 Reply Last reply
    0
    • F frodi

      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;
      
          //if(connectionCheck()==false)
          if(tester)
          {
              // 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("background-color:red");
              //msg.setStyleSheet("QMessageBox:{ background-color:red;}");
      
              // Set connection status led to red
              ui->stat_Label->setText("Not connected!");
              ui->stat_Label->setStyleSheet("color:red;");
          }
      
          else
          {
              ui->stat_Label->setText("Connected");
              ui->stat_Label->setStyleSheet("color:green;");
          }
      
      }
      

      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?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @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).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved