QStatusBar background color changes on repaint

  • Hi,
    I'm having trouble with the status bar on a Qt Widgets Application.

    When my application first launches, the status bar has the right color (native app window gray). However, whenever repaint() is triggered, say from a call to resize or showMessage, the status bar draws a new (slightly darker gray) background color. Can't find anything in the forums, has anyone else seen this?

    Thanks in advance,

    edit: I'm on Mac 10.10, Qt 5.10, and I don't notice this on other OS's.

  • Here's my latest attempt to fix:

    void MainWindow::showEvent(QShowEvent *event)
        // if window gets shown by system
        if (!event->spontaneous())
            QTimer::singleShot(1, ui->statusBar, SLOT(repaint()));

    If anybody has better advice, please post. I mean this is pretty hacky...

  • Qt Champions 2017

    Does it also have this color change on a default QWidgets project ?
    Im asking as far as i can recall, no one ever mentioned this before.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Can you provide a minimal compilable example that reproduces that ?

  • Thanks for your replies.
    @mrjj Hi, yes it is the default QWidgets project.

    The project is using QT Creator 4.5.0. I'm having the problem with Mac OS 10.10 when building with both Qt 5.9.4 and 5.10.0 (clang).

    @SGaist To be thorough, everything is default.


    #include "mainwindow.h"
    #include <QApplication>
    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        MainWindow w;
        return a.exec();


    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <QMainWindow>
    namespace Ui {
    class MainWindow;
    class MainWindow : public QMainWindow
        explicit MainWindow(QWidget *parent = 0);
        Ui::MainWindow *ui;
    #endif // MAINWINDOW_H


    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    MainWindow::MainWindow(QWidget *parent) :
        ui(new Ui::MainWindow)
        delete ui;

  • Lifetime Qt Champion

    Even the UI file ? (The only one that is missing here)

  • @SGaist Yeah, it's default too. Apologies if it's excessive, but I'll put it here as a sanity check.

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <widget class="QMainWindow" name="MainWindow">
      <property name="geometry">
      <property name="windowTitle">
      <widget class="QWidget" name="centralWidget"/>
      <widget class="QMenuBar" name="menuBar">
       <property name="geometry">
      <widget class="QToolBar" name="mainToolBar">
       <attribute name="toolBarArea">
       <attribute name="toolBarBreak">
      <widget class="QStatusBar" name="statusBar"/>
     <layoutdefault spacing="6" margin="11"/>

  • Lifetime Qt Champion

    I've tested it on macOS 10.12 and I'm not sure I seeing that subtle change.

    Do you also see it if you set an empty text on the status bar in the constructor ?

  • Thanks for your suggestion. I tried it and it doesn't seem to fix the issue. So we're sure we're on the same page: I added this line to the constructor:


    For the sake of documentation, I found a way to show both colors simultaneously. Setting a message with a user event, like a triggered push button, before resizing the window results in both status bar colors showing simultaneously like this:

    0_1517523776891_Screen Shot 2018-02-01 at 2.19.57 PM.png

    You can see the lighter white color to the left of the message.

    In any case if it's not happening on MacOS 10.12, then it sounds like a compatibility issue with my older OS. No big deal.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.