View Full Version : QPalette Question
jlgerber
11th November 2006, 18:21
Hello,
I want to define a palette that every widget in my application respects by default.
As a test, i went ahead and used the static method to fetch the palette from QApplication, made various modifications, and then stuffed it back via QAppication::setPalette. Most widgets seemed to obey the modifications except one: QGroupBox. I cannot seem to change its color through the palette. I think that i have tried every roll listed in QPalette.
Are there other rolls which arent listed, or is there no guarantee that stock qt widgets will obay the qapplication palette, or am i going about this all wrong?
Thanks
jonathan
jacek
11th November 2006, 21:40
Maybe:groupBox->setAutoFillBackground( true ); will help?
jlgerber
11th November 2006, 21:57
Maybe:groupBox->setAutoFillBackground( true ); will help?
I will try this but I don't think it makes much sense. What would that have to do with the color of the label and box itself?
The real question i have is about my understanding of how it should work. Is my notion of the application's palette's scope flawed? Is it not ment to govern everything in an application unless specifically overruled?
And thank you for the quick reply. I am excited to have found a good forum for qt.
jonathan
jacek
11th November 2006, 22:16
I will try this but I don't think it makes much sense. What would that have to do with the color of the label and box itself?
How do you expect to see the colour of something that is completely transparent?
Is it not ment to govern everything in an application unless specifically overruled?
Yes, but QPalette doesn't control everything. You might have to create your own style to fully customize the appearance of that widget.
jlgerber
12th November 2006, 03:12
How do you expect to see the colour of something that is completely transparent?
Yes, but QPalette doesn't control everything. You might have to create your own style to fully customize the appearance of that widget.
Eh? I am talking about the frame itself. It is a QGroupBox (creates a frame and label around other widgets). And the problem isnt that i cannot see it; the problem is that it does not respond to changes in the application palette, like every other widget in the program.
I had to do something like this when initializing it to get it to work:
attrBox = new QGroupBox("Attributes");
attrBox->setPalette(QApplication::palette() );
I thought that it would already be initialized with the application's palette.
It was my understanding that every widget in an application shared the same palette initially. is this not true?
jacek
12th November 2006, 18:25
Eh? I am talking about the frame itself. It is a QGroupBox (creates a frame and label around other widgets).
OK, so we are talking about the frame in sense of a line, not in sense of QFrame.
And the problem isnt that i cannot see it; the problem is that it does not respond to changes in the application palette, like every other widget in the program.
Consider this program:
#include <QApplication>
#include <QGroupBox>
#include <QLayout>
#include <QPalette>
#include <QPushButton>
class Test : public QGroupBox
{
Q_OBJECT
public:
Test() : QGroupBox( "test" )
{
QPushButton *b = new QPushButton( "change" );
connect( b, SIGNAL( clicked() ), this, SLOT( changePalette() ) );
QVBoxLayout *l = new QVBoxLayout();
l->addWidget( b );
setLayout( l );
}
private slots:
void changePalette()
{
QPalette p;
p.setColor( QPalette::Dark, Qt::red );
QApplication::setPalette( p );
update();
}
};
int main( int argc, char **argv )
{
QApplication app( argc, argv );
Test t;
t.show();
return app.exec();
}
#include "main.moc"
I've attached two screenshots showing group box with original palette and the same group box after the QApplication palette was changed.
Note that some styles (in this case Plastique) sometimes ignore QPalette settings, so I had to use windows style.
jlgerber
14th November 2006, 17:25
OK, so we are talking about the frame in sense of a line, not in sense of QFrame.
.....
Note that some styles (in this case Plastique) sometimes ignore QPalette settings, so I had to use windows style.
If you had said THAT in the first place, you could have left the code out:) I am using the plastique style.. so that would be a bug then?
jacek
14th November 2006, 20:19
so that would be a bug then?
I would call it a "feature". There is/was a similar issue with windows XP style and button colours.
You can always contact the Trolls and say you would like to able to change that line colour in Plastique too. If this is a common query, they might implement it. Other solution is to implement your own style.
vBulletin® v3.7.1, Copyright ©2000-2008, Jelsoft Enterprises Ltd.