Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

QMainWindow->setStyleSheet behaves unexpected (Q_OBJECT causing problems?)

$
0
0
Using Qt 4.8.4 on Windows 7 (MSVC 2010) I have a standard QMainWindow in my app with toolbar and menu. I want to achieve that toolbar and menu keep their grey color, but the central widget should have a white background. My test case is an app with just one label in the central widget. In order to see the problem, add or remove the Q_OBJECT line in test.h When Q_OBJECT is there, only the label gets a white bg. If Q_OBJECT is commented out, the whole central widget is white. Of course, I want the whole area white, but also need Q_OBJECT. Here’s the files: main.cpp: #include "test.h"   class testwin : public QMainWindow { public:     QWidget     *centralWidget;     QToolBar    *mainToolBar;       testwin(QWidget *parent = 0) : QMainWindow(parent) {         centralWidget = new test(this);         setCentralWidget(centralWidget);         mainToolBar = new QToolBar(this);         this->addToolBar(Qt::TopToolBarArea, mainToolBar);     };       ~testwin() {}; };   int main(int argc, char *argv[]) {     QApplication a(argc, argv);     testwin w;     w.centralWidget->setStyleSheet("background-color: white;");     w.show();     return a.exec(); } test.h: #ifndef TEST_H #define TEST_H   #include <QtGui>   class test : public QWidget {     Q_OBJECT    // remove this   public:     QLabel *label;       test(QWidget *parent = 0) {         resize(400, 300);         label = new QLabel(this);         label->setText("Test");     }; };   #endif // TEST_H

Viewing all articles
Browse latest Browse all 13965

Trending Articles