hello! i have a simple child widgets question
Hello. I'm trying to make a widget and a child widget. I'd like Widget2 to be a child of Widget. Would anybody be able to check if I'm doing it right. Thanx
main.cpp:
Code:
.......
Widget2::Widget2(Widget* parent): Widget(parent)
{
}
{
}
......
hfile.h
Code:
#ifndef HFILE_H
#define HFILE_H
#include <QtGui>
{
Q_OBJECT
public:
protected:
private:
};
class Widget2 : public Widget
{
Q_OBJECT
public:
protected:
private:
};
#endif
Re: hello! i have a simple child widgets question
Your code makes Widget2 inherit Widget (which, in turn inherits QWidget). This gives you an is-a relationship, i.e. Widget2 is-a Widget. This is usually not what you call a child widget.
Child widgets are widgets that have a parent. This is called a has-a relationship. The parent has-a child. For example:
Here w1 has-a w2, i.e. w2 is a child widget to w1.
Re: hello! i have a simple child widgets question
Thanx for your clarification.
So, in your example w2 is a child of w1, right?
Can any QWidget be a child of another?
For example: can QWidget be a child of QLabel, or only the other way around is allowed(because of the resaons how they inherit from one another)?
Re: hello! i have a simple child widgets question
Quote:
Originally Posted by
ht1
Can any QWidget be a child of another?
Yes, but sometimes it doesn't make much sense (like making a scrollbar a child of a pushbutton).