#include <ParentTestApp.h>
// ------------------------------------------------------------
// ------------------------------------------------------------
//main program execution loop
// ------------------------------------------------------------
// ------------------------------------------------------------
int main(int argc, char *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;
//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
::black);
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->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
{
}
//changes the background color of the widget
void ChildClass::ColorMe(void)
{
//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
::green);
this->setPalette(qTempPalette);
}
Bookmarks