[Qt-interest] Basic question on QWidget

Nitin Mahajan nitinm76 at yahoo.com
Fri Jan 1 17:36:38 CET 2010


Hello Abhishek,

--- On Fri, 1/1/10, Abhishek Patil <abhishekworld at gmail.com> wrote:

> From: Abhishek Patil <abhishekworld at gmail.com>
> Subject: Re: [Qt-interest] Basic question on QWidget
> To: qt-interest at trolltech.com, nitinm76 at yahoo.com
> Date: Friday, 1 January, 2010, 9:27 PM
> Hi Nitin,
> so what i get from your description ...
> 
> On Friday 01 Jan 2010 7:51:57 pm Nitin Mahajan wrote:
> > HI!
> > 
> > I have a basic question about QWidget.
> > 
> > I have derived a class A from QWidget and class B also
> from QWidget.
> > 
> > Class B has a HBoxLayout and has only QSlider object
> added to it.
> > 
> > In class A's constructor When I crate a object of
> class B with parent as A,
> > I can see only the slider and not the Widget B itself.
> I do a proper
> >  setGeometry for B, but it changes only the
> length of slider and does not
> >  show Widget B at all.
> till here i came up with this program...
> /*Test.h*/
> #include <QWidget>
> #include <QHBoxLayout>
> #include <QSlider>
> 
> class A : public QWidget
> {
>   public:
>   A(QWidget* parent=0);
>   ~A();
> };
> 
> class B : public QWidget
> {
>   public:
>   B(QWidget* parent=0);
>   ~B();
> 
>   private:
>   QHBoxLayout* layout;
>   QSlider* slider;
> };
> 
> /*Test.cpp*/
> 
> #include <QWidget>
> #include "test.h"
> 
> class B;
> 
> A::A(QWidget* parent)
>   :QWidget(parent)
> {
>   B* obj = new B(this);
> }
> 
> A::~A(){}
> 
> B::B(QWidget* parent)
>   :QWidget(parent)
> {
>   layout = new QHBoxLayout(this);
>   slider = new QSlider(this);
>   layout->addWidget(slider);
> }
> 
> B::~B(){}
> 
> /* main.cpp*/
> 
> #include <QApplication>
> #include "test.h"
> 
> int main(int argc, char** argv)
> {
>   QApplication app(argc,argv);
>   A a;
>   a.show();
>   return app.exec();
> }
> 
> in above program B is your custom widget which show
> "QSlider in QHBoxLayout "  
> so if you create an object of B in A (  B* obj = new
> B(this); ) where parent of 
> B is A  obviously  B will get inside A as the
> line B* obj = new B(this); in A 
> Constructor says paint B inside (A) (not the exact meaning
> but for your 
> understanding). so if u remove Slider form B, B is getting
> printed inside A but 
> theres nothing to show (as theres no slider or something
> else) so how you will 
> get something to see.
> 
> 
> > When I remove Slider from B, I cannot see B's widget
> at all bing displayed
> >  as a Child of A.
> > 
> > Now I created one more object directly from QWidget
> and set A as parent. It
> >  shows, where as if the child is derived from
> QWidget it does not show up
> >  at all. Can someone please give me some pointers
> towards whats the basic
> >  thing that is going wrong here?
> 
> could your please explain this part .... code will be more
> useful.. 
Thanks for creating the code from the explaination. 

Here is the second situation.

A::A(QWidget* parent)
   :QWidget(parent)
 {
   QWidget*  obj = new QWidget(this);
 }

regards

-Nitin
> 
> > regards
> > 
> > -Nitin
> > 
> > 
> > 
> > 
> >       New Email names for
> you!
> > Get the Email name you've always wanted on the new
> @ymail and
> >  @rocketmail. Hurry before someone else does!
> > http://mail.promotions.yahoo.com/newdomains/aa/
> > 
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
> > 
> 
> enjoy
> - Abhishek 
> 


      New Email addresses available on Yahoo!
Get the Email name you&#39;ve always wanted on the new @ymail and @rocketmail. 
Hurry before someone else does!
http://mail.promotions.yahoo.com/newdomains/aa/




More information about the Qt-interest-old mailing list