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. QStatusBar background color changes on repaint

QStatusBar background color changes on repaint

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 2.0k Views
  • 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.
  • E Offline
    E Offline
    Elliot
    wrote on last edited by Elliot
    #1

    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,
    Elliot

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

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Elliot
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        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.

        E 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi and welcome to devnet,

          Can you provide a minimal compilable example that reproduces that ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • mrjjM mrjj

            Hi
            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.

            E Offline
            E Offline
            Elliot
            wrote on last edited by Elliot
            #5

            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.

            main.cpp:

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

            mainwindow.h:

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

            mainwindow.cpp

            #include "mainwindow.h"
            #include "ui_mainwindow.h"
            
            MainWindow::MainWindow(QWidget *parent) :
                QMainWindow(parent),
                ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
            }
            
            MainWindow::~MainWindow()
            {
                delete ui;
            }
            
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              E 1 Reply Last reply
              0
              • SGaistS SGaist

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

                E Offline
                E Offline
                Elliot
                wrote on last edited by
                #7

                @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">
                 <class>MainWindow</class>
                 <widget class="QMainWindow" name="MainWindow">
                  <property name="geometry">
                   <rect>
                    <x>0</x>
                    <y>0</y>
                    <width>400</width>
                    <height>300</height>
                   </rect>
                  </property>
                  <property name="windowTitle">
                   <string>MainWindow</string>
                  </property>
                  <widget class="QWidget" name="centralWidget"/>
                  <widget class="QMenuBar" name="menuBar">
                   <property name="geometry">
                    <rect>
                     <x>0</x>
                     <y>0</y>
                     <width>400</width>
                     <height>22</height>
                    </rect>
                   </property>
                  </widget>
                  <widget class="QToolBar" name="mainToolBar">
                   <attribute name="toolBarArea">
                    <enum>TopToolBarArea</enum>
                   </attribute>
                   <attribute name="toolBarBreak">
                    <bool>false</bool>
                   </attribute>
                  </widget>
                  <widget class="QStatusBar" name="statusBar"/>
                 </widget>
                 <layoutdefault spacing="6" margin="11"/>
                 <resources/>
                 <connections/>
                </ui>
                
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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 ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  E 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    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 ?

                    E Offline
                    E Offline
                    Elliot
                    wrote on last edited by
                    #9

                    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:

                    ui->statusBar->showMessage(QString());
                    

                    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.

                    1 Reply Last reply
                    0

                    • Login

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