PDA

View Full Version : Combine Widgets in a new class



sedi
29th January 2012, 18:19
Hi,
I'm trying to build a new class that provides a combination of two QWidgets: one title bar and one collapsible (->hideable) content widget ("panel"). As I will need several very different panel layouts I have an "abstract" (not really virtual) class that is inherited - the heir doesn't change anything as of now, though.

The code compiles, but I don't see the desired appearance - As for now I have put a QPushButton in titleBarWidget and panelWidget, but both seem to be displayed on top of each other.

I am pretty sure it is a very simple beginner's problem. I am very new to C++ and Qt so I might be lacking a very basic concept here. My code:


AbstractCont::AbstractCont(QWidget *parent) :
QWidget(parent)
{

this->setVisible(true);
this->resize(400,400);
this->show();

this->titleBarWidget = new QWidget(this);
this->titleBarWidget->setVisible(true);
this->titleBarWidget->resize(100,100);
this->titleBarWidget->show();
this->titleBarWidget->setBackgroundRole(QPalette::Window);

QPushButton *pushButt1 = new QPushButton("Title", this->titleBarWidget);
pushButt1->resize(50,50);
pushButt1->show();

this->panelWidget=new QWidget(this);
this->panelWidget->setVisible(true);
this->panelWidget->resize(100,100);
this->panelWidget->show();

QPushButton *pushButt2 = new QPushButton("Panel", this->panelWidget);
pushButt2->resize(50,50);
pushButt2->show();
}

This is used by:


Cont_Anwesenheit::Cont_Anwesenheit(...):AbstractCo nt(parent)
{
};

Which is again called by:

AbstractCont *cont = new Cont_Anwesenheit("Die ID","Kursname", this->model, this->scene, dock);

The variable cont has to be able to hold different heritages of AbstractCont, thus the type.

What I see is attached: just the Button with "Panel". What I like to achieve (just an example, not exactly) is also attached

Any help would be gratefully appreciated!

Best Regards,
Sebastian

ChrisW67
29th January 2012, 22:55
Read about Layout Management

sedi
30th January 2012, 10:25
Oops. Seems like I haven't seen the wood for the trees. Learning is an embarrassing thing to to :-) Thank you!