thawkins
2nd June 2006, 18:05
Hi all,
I just recently moved from Qt 4.0.0/4.0.1 to Qt 4.1.3. I had some code that instantiated a bunch of QWidget derived classes to be children of another QWidget derived class. In Qt 4.0.X the code produced the results shown in the attached Qt400Result.jpg. In Qt 4.1.3, the results of the same code is shown in Qt413Result.jpg. I intentionally manipulate the palettes after the initial show() is called, and not during the constructors, yet it seems like I can't change the childrens palettes from what the parent was set to.
I know the change log for Qt 4.1.0 (http://www.trolltech.com/developer/notes/changes/changes-4.1.0/) said "Child widgets now always inherit the contents of their parent.", but I should be able to change the childrens palette yes? I've attached a stripped down working version of my code that reproduces the problem, any help would be appreciated.
I'm using Qt 4.1.3 on an x11 platform
The cpp file (ParentTestApp.cpp)
#include <ParentTestApp.h>
// ------------------------------------------------------------
// ------------------------------------------------------------
//main program execution loop
// ------------------------------------------------------------
// ------------------------------------------------------------
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
ParentClass pParentTest;
// instantiating the main class for this app and
// calling ColorizeChildren() to change the childrens
// background color to green
pParentTest.show();
pParentTest.ColorizeChildren();
//go thread go!
return app.exec();
}
// ------------------------------------------------------------
// ------------------------------------------------------------
// ParentClass implementation
// ------------------------------------------------------------
// ------------------------------------------------------------
//default constructor for the main class for this app
ParentClass::ParentClass()
{
int i;
QPalette qTempPalette;
//setting the background color to black. I know that in
//4.1.3 QPalette::Background is replaced by QPalette::Window however,
//same results occur in 4.1.3 with either enum
qTempPalette = this->palette();
qTempPalette.setColor(QPalette::Background,Qt::bla ck);
this->setPalette(qTempPalette);
//changing the size of the main widget
resize(400,100);
//making the children and placing them into a horizontal box
//layout
for (i = 0; i < 4; i++)
{
this->pChildren[i] = new ChildClass(this);
this->pChildren[i]->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ig nored);
this->qMainLayout.addWidget(this->pChildren[i]);
}
//setting the layout
this->setLayout(&this->qMainLayout);
}
//basic destructor type class
ParentClass::~ParentClass()
{
int i;
//buh-bye children!
for (i = 0; i < 4; i++) delete this->pChildren[i];
}
void ParentClass::ColorizeChildren(void)
{
int i;
//giving the children color
for (i = 0; i < 4; i++) this->pChildren[i]->ColorMe();
}
// ------------------------------------------------------------
// ------------------------------------------------------------
// ChildClass implementation
// ------------------------------------------------------------
// ------------------------------------------------------------
//basic constructor
ChildClass::ChildClass(QWidget *pParent) : QWidget(pParent)
{
}
//changes the background color of the widget
void ChildClass::ColorMe(void)
{
QPalette qTempPalette;
//setting the background color to green. I know that in
//4.1.3 QPalette::Background is replaced by QPalette::Window however,
//same results occur in 4.1.3 with either enum
qTempPalette = this->palette();
qTempPalette.setColor(QPalette::Background,Qt::gre en);
this->setPalette(qTempPalette);
}
The h file (ParentTestApp.h)
#include <QApplication>
#include <QWidget>
#include <QHBoxLayout>
#include <QPalette>
// ------------------------------------------------------------
// ------------------------------------------------------------
// Object prototypes
// ------------------------------------------------------------
// ------------------------------------------------------------
class ChildClass;
class ParentClass;
class ParentClass : public QWidget
{
Q_OBJECT;
public:
ParentClass();
~ParentClass();
void ColorizeChildren(void);
private:
ChildClass *pChildren[4];
QHBoxLayout qMainLayout;
};
//the children of ParentClass
class ChildClass : public QWidget
{
Q_OBJECT;
public:
ChildClass(QWidget *pParent);
void ColorMe(void);
};
I just recently moved from Qt 4.0.0/4.0.1 to Qt 4.1.3. I had some code that instantiated a bunch of QWidget derived classes to be children of another QWidget derived class. In Qt 4.0.X the code produced the results shown in the attached Qt400Result.jpg. In Qt 4.1.3, the results of the same code is shown in Qt413Result.jpg. I intentionally manipulate the palettes after the initial show() is called, and not during the constructors, yet it seems like I can't change the childrens palettes from what the parent was set to.
I know the change log for Qt 4.1.0 (http://www.trolltech.com/developer/notes/changes/changes-4.1.0/) said "Child widgets now always inherit the contents of their parent.", but I should be able to change the childrens palette yes? I've attached a stripped down working version of my code that reproduces the problem, any help would be appreciated.
I'm using Qt 4.1.3 on an x11 platform
The cpp file (ParentTestApp.cpp)
#include <ParentTestApp.h>
// ------------------------------------------------------------
// ------------------------------------------------------------
//main program execution loop
// ------------------------------------------------------------
// ------------------------------------------------------------
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
ParentClass pParentTest;
// instantiating the main class for this app and
// calling ColorizeChildren() to change the childrens
// background color to green
pParentTest.show();
pParentTest.ColorizeChildren();
//go thread go!
return app.exec();
}
// ------------------------------------------------------------
// ------------------------------------------------------------
// ParentClass implementation
// ------------------------------------------------------------
// ------------------------------------------------------------
//default constructor for the main class for this app
ParentClass::ParentClass()
{
int i;
QPalette qTempPalette;
//setting the background color to black. I know that in
//4.1.3 QPalette::Background is replaced by QPalette::Window however,
//same results occur in 4.1.3 with either enum
qTempPalette = this->palette();
qTempPalette.setColor(QPalette::Background,Qt::bla ck);
this->setPalette(qTempPalette);
//changing the size of the main widget
resize(400,100);
//making the children and placing them into a horizontal box
//layout
for (i = 0; i < 4; i++)
{
this->pChildren[i] = new ChildClass(this);
this->pChildren[i]->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ig nored);
this->qMainLayout.addWidget(this->pChildren[i]);
}
//setting the layout
this->setLayout(&this->qMainLayout);
}
//basic destructor type class
ParentClass::~ParentClass()
{
int i;
//buh-bye children!
for (i = 0; i < 4; i++) delete this->pChildren[i];
}
void ParentClass::ColorizeChildren(void)
{
int i;
//giving the children color
for (i = 0; i < 4; i++) this->pChildren[i]->ColorMe();
}
// ------------------------------------------------------------
// ------------------------------------------------------------
// ChildClass implementation
// ------------------------------------------------------------
// ------------------------------------------------------------
//basic constructor
ChildClass::ChildClass(QWidget *pParent) : QWidget(pParent)
{
}
//changes the background color of the widget
void ChildClass::ColorMe(void)
{
QPalette qTempPalette;
//setting the background color to green. I know that in
//4.1.3 QPalette::Background is replaced by QPalette::Window however,
//same results occur in 4.1.3 with either enum
qTempPalette = this->palette();
qTempPalette.setColor(QPalette::Background,Qt::gre en);
this->setPalette(qTempPalette);
}
The h file (ParentTestApp.h)
#include <QApplication>
#include <QWidget>
#include <QHBoxLayout>
#include <QPalette>
// ------------------------------------------------------------
// ------------------------------------------------------------
// Object prototypes
// ------------------------------------------------------------
// ------------------------------------------------------------
class ChildClass;
class ParentClass;
class ParentClass : public QWidget
{
Q_OBJECT;
public:
ParentClass();
~ParentClass();
void ColorizeChildren(void);
private:
ChildClass *pChildren[4];
QHBoxLayout qMainLayout;
};
//the children of ParentClass
class ChildClass : public QWidget
{
Q_OBJECT;
public:
ChildClass(QWidget *pParent);
void ColorMe(void);
};