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,
Elliotedit: 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...
-
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. -
Hi and welcome to devnet,
Can you provide a minimal compilable example that reproduces that ?
-
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.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; }
-
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"> <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>
-
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 ?
-
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:
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:
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.