Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, January 2008
Newbie problem: Widget derived from QWidget not showing


Message 1 in thread

Hi,
 I have a silly problem that surely has a simple explanation, but I can't figure it out. I have a mainwindow application that has a toolbox on the left and a frame on the right. When someone clicks a button on the toolbar, my intent is to load a widget into the frame. 

 For this, I have subclassed a class like this:

class My : public QWidget {
    Q_OBJECT
    private:
        QTextEdit *e;
    public:
        My(QWidget *p = 0)
        {
            e = new QTextEdit(p);
        }
};

 And when someone clicks a button, I have code such as this:

QHBoxLayout *moduleLayout = new QHBoxLayout(view); //view is the frame
My *e = new My(view); // does not work!
moduleLayout->addWidget(e);  

 With this, no widget appears when the button is clicked. However, if I replace "My" with "QTextEdit", such as:

QHBoxLayout *moduleLayout = new QHBoxLayout(view); //view is the frame
QTextEdit *e = new QTextEdit(view); // works!
 moduleLayout->addWidget(e);  

then this works perfectly. Can anyone please help me out?

Thanks a ton in advance.
Rajorshi
 

       
---------------------------------
Looking for last minute shopping deals?  Find them fast with Yahoo! Search.

Message 2 in thread

The issue is... the My class hasa QTextEdit not isa QTextEdit...

 

So, when you are adding a My... you are placing a QWidget... Then QT
says... lets layout all the children... But since non of them are
layedout..your not seeing any of them

 

 

Try this in the constructor

 

My( QWdiget * p = 0 )

{

   QVBoxLayout * l = new QVBoxLayout( this );

   l->addWidget( e = new QTextEdit );

}

 

Scott

 

________________________________

From: Rajorshi Biswas [mailto:rajorshi_iiitc@xxxxxxxxx] 
Sent: Saturday, January 26, 2008 11:45 AM
To: qt-interest@xxxxxxxxxxxxx
Subject: Newbie problem: Widget derived from QWidget not showing

 

Hi,
 I have a silly problem that surely has a simple explanation, but I
can't figure it out. I have a mainwindow application that has a toolbox
on the left and a frame on the right. When someone clicks a button on
the toolbar, my intent is to load a widget into the frame. 

 For this, I have subclassed a class like this:

class My : public QWidget {
    Q_OBJECT
    private:
        QTextEdit *e;
    public:
        My(QWidget *p = 0)
        {
            e = new QTextEdit(p);
        }
};

 And when someone clicks a button, I have code such as this:

QHBoxLayout *moduleLayout = new QHBoxLayout(view); //view is the frame
My *e = new My(view); // does not work!
moduleLayout->addWidget(e);  

 With this, no widget appears when the button is clicked. However, if I
replace "My" with "QTextEdit", such as:

QHBoxLayout *moduleLayout = new QHBoxLayout(view); //view is the frame
QTextEdit *e = new QTextEdit(view); // works!
moduleLayout->addWidget(e);  

then this works perfectly. Can anyone please help me out?

Thanks a ton in advance.
Rajorshi

  

________________________________

Looking for last minute shopping deals? Find them fast with Yahoo!
Search.
<http://us.rd.yahoo.com/evt=51734/*http:/tools.search.yahoo.com/newsearc
h/category.php?category=shopping> 


Message 3 in thread

Works!

Thanks for the awesome explanation :-) :-)

~Rajorshi

Scott Aron Bloom <Scott.Bloom@xxxxxxxxxxxx> wrote:        v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);}           The issue is? the My class hasa QTextEdit not isa QTextEdit?
   
  So, when you are adding a My? you are placing a QWidget? Then QT says? lets layout all the children? But since non of them are layedout..your not seeing any of them
   
   
  Try this in the constructor
   
  My( QWdiget * p = 0 )
  {
     QVBoxLayout * l = new QVBoxLayout( this );
     l->addWidget( e = new QTextEdit );
  }
   
  Scott
   
        
---------------------------------
  
  From: Rajorshi Biswas [mailto:rajorshi_iiitc@xxxxxxxxx] 
 Sent: Saturday, January 26, 2008 11:45 AM
 To: qt-interest@xxxxxxxxxxxxx
 Subject: Newbie problem: Widget derived from QWidget not showing
  
   
  Hi,
  I have a silly problem that surely has a simple explanation, but I can't figure it out. I have a mainwindow application that has a toolbox on the left and a frame on the right. When someone clicks a button on the toolbar, my intent is to load a widget into the frame. 
 
  For this, I have subclassed a class like this:
 
 class My : public QWidget {
     Q_OBJECT
     private:
         QTextEdit *e;
     public:
         My(QWidget *p = 0)
         {
             e = new QTextEdit(p);
         }
 };
 
  And when someone clicks a button, I have code such as this:
 
 QHBoxLayout *moduleLayout = new QHBoxLayout(view); //view is the frame
 My *e = new My(view); // does not work!
 moduleLayout->addWidget(e);  
 
  With this, no widget appears when the button is clicked. However, if I replace "My" with "QTextEdit", such as:
 
 QHBoxLayout *moduleLayout = new QHBoxLayout(view); //view is the frame
 QTextEdit *e = new QTextEdit(view); // works!
 moduleLayout->addWidget(e);  
 
 then this works perfectly. Can anyone please help me out?
 
 Thanks a ton in advance.
 Rajorshi
    
    
---------------------------------
  
  Looking for last minute shopping deals? Find them fast with Yahoo! Search.
  
  
  

       
---------------------------------
Looking for last minute shopping deals?  Find them fast with Yahoo! Search.

Message 4 in thread

Rajorshi Biswas wrote:
>        My(QWidget *p = 0)
>        {
>            e = new QTextEdit(p);
>        }

Change the above to:
   My(QWidget *p = 0) : QWidget(p)
   {
      e = new QTextEdit(this);
   }

Without code, your widget of class "My" has no parent. Therefore, it's a 
top-level widget. When you show your view, it doesn't get shown (it's not 
part of that view).

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.