[Qt-interest] Fwd: widget promotion
Andreas Pakulat
apaku at gmx.de
Sat Dec 27 19:47:18 CET 2008
On 27.12.08 16:11:37, ami guru wrote:
> It did work.
>
> But i need to clear up some confusion.
>
> I have myClass as a subclass of QGraphicsView.
>
> Now if i want to use myClass as a widget in the designer
> then is that must i have to use QGraphicsView as a place-holder.
Right.
> Lets try to analyze to the what you have suggested.
>
> class H3DNodeView : public QGraphicsView
> {
> H3DNodeView(QWidget *parent) : QGraphicsView(parent)
> {
>
> }
> };
>
>
> I opended the ui_***.h file found as follows:
>
> //my custimized class
> H3DNodeView *graphicsView;
>
> treeViewH3D = new QTreeView(centralwidget);
>
>
> the constructor takes a pointer to the QWidget and
> set that as the parent of the QGraphicsView and that makes sense.
This is a C++ thing and doesn't have something to do with Qt: after the
colon in the constructor of H3DNodeView the first thing should be the call
to the parent class constructor, including needed parameters to the parent
class. Your class subclasses from QGraphicsView, so it must call the
QGraphicsView constructor. The compiler error told you that you tried to
call the QWidget constructor, which is not a direct base class of
H3DNodeView.
The QWidget* parent parameter is a different beast, its expected by the
uic-generated code to create the needed inheritance relationship and in
your custom class you just pass it on to the parent class constructor.
Andreas
--
Your lover will never wish to leave you.
More information about the Qt-interest-old
mailing list