How to change empty editor color?
Code:
MainWindow::MainWindow() {
createMenus();
edit = new CodeEditor();
//tabWidget->addTab(edit, "1");
setCentralWidget(tabWidget);
}
If I write "tabWidget->add", is OK, one tab.
If not, is empty editor. Its color is white, I prefer gray and don't know, I must change MainWindow background color or empty QTabWidget background color (which is central widget)
Re: How to change empty editor color?
Retrieve the QPalette for the QTabWidget after it is created, set the QPalette::Window color to whatever you want, then set it back on the QTabWidget:
Code:
tabWidget->setPalette( pal );
Re: How to change empty editor color?
I changed all to red, but still is white,...
Code:
for (int i=0; i<QPalette::NColorRoles; i++) {
}
tabWidget->setPalette(pal);
Re: How to change empty editor color?
Quote:
I changed all to red, but still is white,...
Then I guess there is something in the QTabWidget painting code that ignores the palette. The QTabWidget is a compound widget - it consists of a QTabBar and a QStackedWidget that holds the widget for each tab. The tab bar interacts with the stacked widget to change which widget is on top. The stacked widget is not accessible through the QTabWidget API, so it is not possible to set its palette directly.
The only workaround I can think of is to create a tab with an empty QWidget and set the Window color for that. When you are ready to add a real widget (your CodeEditor, for example), add a new tab and then delete the empty one.
Re: How to change empty editor color?
As d_stranz mentioned, you probably need to loop through all the child widgets.
"mainWidget" here can be anything, either your main window, in which case this code will color all child widgets in your app (this is how you create a "color theme"), or it can be your QTabWidget, in which case it should solve your problem.
Code:
// Loop through all child widgets of the main widget and apply the color settings
QList<QWidget*> widgets = mainWidget->findChildren<QWidget*>();
{
w->setPalette(p);
w->update();
}