PDA

View Full Version : Widget Palette



QbelcorT
26th January 2009, 15:21
Hi,
Not sure if this post is in the right place. It is a basic question. I have created many ui forms in QtDesigner. I want each form to have the same palette. Right now I am just setting the palette in QtDesigner to custom, then put the same value in for each form. How can I globally set the palette for all my forms?
Thanks in Advance.

jpn
26th January 2009, 15:24
You could construct the palette in code instead and set it to the whole application through QApplication::setPalette().

QbelcorT
26th January 2009, 15:50
Thank you
I thought maybe I might need this function QApplication::setPalette(). OK, but I look at the designer code for setting the palette and there is like 25 or more lines of code (for the buttons, background, on/off state, etc).
Are you suggesting I put that same designer code outside my form in my window app? Maybe I am misunderstanding your response.

jpn
26th January 2009, 16:17
If you are not comfortable doing it in code, you could also keep it in one of the forms (the main window form would be the natural choice) and set it as application palette after loading the form, more or less like this:


#include <QApplication>

MyMainWindow::MyMainWindow(QWidget* parent) : QMainWindow(parent)
{
ui.setupUi(this);
QApplication::setPalette(palette());
}

This would ensure that other forms inherit the same palette even if you don't explicitly define any.